use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class SubmoduleSectionParser method parse.
private SubmoduleSubscription parse(final String id) {
final String url = bbc.getString("submodule", id, "url");
final String path = bbc.getString("submodule", id, "path");
String branch = bbc.getString("submodule", id, "branch");
try {
if (url != null && url.length() > 0 && path != null && path.length() > 0 && branch != null && branch.length() > 0) {
// All required fields filled.
String project;
if (branch.equals(".")) {
branch = superProjectBranch.get();
}
// relative URL
if (url.startsWith("../")) {
// prefix with a slash for easier relative path walks
project = '/' + superProjectBranch.getParentKey().get();
String hostPart = url;
while (hostPart.startsWith("../")) {
int lastSlash = project.lastIndexOf('/');
if (lastSlash < 0) {
// too many levels up, ignore for now
return null;
}
project = project.substring(0, lastSlash);
hostPart = hostPart.substring(3);
}
project = project + "/" + hostPart;
// remove leading '/'
project = project.substring(1);
} else {
// It is actually an URI. It could be ssh://localhost/project-a.
URI targetServerURI = new URI(url);
URI thisServerURI = new URI(canonicalWebUrl);
String thisHost = thisServerURI.getHost();
String targetHost = targetServerURI.getHost();
if (thisHost == null || targetHost == null || !targetHost.equalsIgnoreCase(thisHost)) {
return null;
}
String p1 = targetServerURI.getPath();
String p2 = thisServerURI.getPath();
if (!p1.startsWith(p2)) {
// http://server/other-teams-gerrit/
return null;
}
// skip common part
project = p1.substring(p2.length());
}
while (project.startsWith("/")) {
project = project.substring(1);
}
if (project.endsWith(Constants.DOT_GIT_EXT)) {
project = project.substring(//
0, project.length() - Constants.DOT_GIT_EXT.length());
}
Project.NameKey projectKey = new Project.NameKey(project);
return new SubmoduleSubscription(superProjectBranch, new Branch.NameKey(projectKey, branch), path);
}
} catch (URISyntaxException e) {
// Error in url syntax (in fact it is uri syntax)
}
return null;
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class SubmitByMergeIfNecessaryIT method testPreviewSubmitTgz.
@Test
public void testPreviewSubmitTgz() throws Exception {
Project.NameKey p1 = createProject("project-name");
TestRepository<?> repo1 = cloneProject(p1);
PushOneCommit.Result change1 = createChange(repo1, "master", "test", "a.txt", "1", "topic");
approve(change1.getChangeId());
// get a preview before submitting:
File tempfile;
try (BinaryResult request = submitPreview(change1.getChangeId(), "tgz")) {
assertThat(request.getContentType()).isEqualTo("application/x-gzip");
tempfile = File.createTempFile("test", null);
request.writeTo(Files.newOutputStream(tempfile.toPath()));
}
InputStream is = new GZIPInputStream(Files.newInputStream(tempfile.toPath()));
List<String> untarredFiles = new ArrayList<>();
try (TarArchiveInputStream tarInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is)) {
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
untarredFiles.add(entry.getName());
}
}
assertThat(untarredFiles).containsExactly(name("project-name") + ".git");
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class CreateProjectIT method withValidGroupName.
@Test
public void withValidGroupName() throws Exception {
String newGroupName = "newGroup";
adminRestSession.put("/groups/" + newGroupName);
String newProjectName = "newProject";
adminSshSession.exec("gerrit create-project --branch master --owner " + newGroupName + " " + newProjectName);
assert_().withFailureMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
assertThat(projectState).isNotNull();
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class CreateProjectIT method withInvalidGroupName.
@Test
public void withInvalidGroupName() throws Exception {
String newGroupName = "newGroup";
adminRestSession.put("/groups/" + newGroupName);
String wrongGroupName = "newG";
String newProjectName = "newProject";
adminSshSession.exec("gerrit create-project --branch master --owner " + wrongGroupName + " " + newProjectName);
assert_().withFailureMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isTrue();
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
assertThat(projectState).isNull();
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchProjectNotifyOnDraftChange.
@Test
public void watchProjectNotifyOnDraftChange() throws Exception {
String watchedProject = createProject("watchedProject").get();
// create group that can view all drafts
GroupInfo groupThatCanViewDrafts = gApi.groups().create("groupThatCanViewDrafts").get();
grant(new Project.NameKey(watchedProject), "refs/*", Permission.VIEW_DRAFTS, false, new AccountGroup.UUID(groupThatCanViewDrafts.id));
// watch project as user that can't view drafts
setApiUser(user);
watch(watchedProject, null);
// watch project as user that can view all drafts
TestAccount userThatCanViewDrafts = accounts.create("user2", "user2@test.com", "User2", groupThatCanViewDrafts.name);
setApiUser(userThatCanViewDrafts);
watch(watchedProject, null);
// push a draft change to watched project -> should trigger email notification for
// userThatCanViewDrafts, but not for user
setApiUser(admin);
TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER", "a", "a1").to("refs/for/master%draft");
r.assertOkStatus();
// assert email notification
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(userThatCanViewDrafts.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Aggregations