use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class SetParentCommand method run.
@Override
protected void run() throws Failure {
enableGracefulStop();
if (oldParent == null && children.isEmpty()) {
throw die("child projects have to be specified as " + "arguments or the --children-of option has to be set");
}
if (oldParent == null && !excludedChildren.isEmpty()) {
throw die("--exclude can only be used together with --children-of");
}
final StringBuilder err = new StringBuilder();
if (newParent != null) {
newParentKey = newParent.getProject().getNameKey();
}
final List<Project.NameKey> childProjects = children.stream().map(ProjectState::getNameKey).collect(toList());
if (oldParent != null) {
try {
childProjects.addAll(getChildrenForReparenting(oldParent));
} catch (PermissionBackendException e) {
throw new Failure(1, "permissions unavailable", e);
} catch (Exception e) {
throw new Failure(1, "failure in request", e);
}
}
for (Project.NameKey nameKey : childProjects) {
final String name = nameKey.get();
ProjectState project = projectCache.get(nameKey).orElseThrow(illegalState(nameKey));
try {
setParent.apply(new ProjectResource(project, user), parentInput(newParentKey.get()));
} catch (AuthException e) {
err.append("error: insuffient access rights to change parent of '").append(name).append("'\n");
} catch (ResourceConflictException | ResourceNotFoundException | BadRequestException e) {
err.append("error: ").append(e.getMessage()).append("'\n");
} catch (UnprocessableEntityException | IOException e) {
throw new Failure(1, "failure in request", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "permissions unavailable", e);
}
}
if (err.length() > 0) {
while (err.charAt(err.length() - 1) == '\n') {
err.setLength(err.length() - 1);
}
throw die(err.toString());
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class CreateProjectCommand method run.
@Override
protected void run() throws Failure {
enableGracefulStop();
try {
if (!suggestParent) {
if (projectName == null) {
throw die("Project name is required.");
}
ProjectInput input = new ProjectInput();
input.name = projectName;
if (ownerIds != null) {
input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
}
if (newParent != null) {
input.parent = newParent.getName();
}
input.permissionsOnly = permissionsOnly;
input.description = projectDescription;
input.submitType = submitType;
input.useContributorAgreements = contributorAgreements;
input.useSignedOffBy = signedOffBy;
input.useContentMerge = contentMerge;
input.requireChangeId = requireChangeID;
input.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
input.branches = branch;
input.createEmptyCommit = createEmptyCommit;
input.maxObjectSizeLimit = maxObjectSizeLimit;
input.rejectEmptyCommit = rejectEmptyCommit;
if (pluginConfigValues != null) {
input.pluginConfigValues = parsePluginConfigValues(pluginConfigValues);
}
gApi.projects().create(input);
} else {
for (Project.NameKey parent : suggestParentCandidates.getNameKeys()) {
stdout.print(parent.get() + '\n');
}
}
} catch (RestApiException err) {
throw die(err);
} catch (PermissionBackendException err) {
throw new Failure(1, "permissions unavailable", err);
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmitTopic.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void xGerritUpdatedRefSetMultipleHeadersForSubmitTopic() throws Exception {
String secondProject = "secondProject";
projectOperations.newProject().name(secondProject).create();
TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
String topic = "topic";
String branch = "refs/heads/master";
Result change1 = createChange(testRepo, branch, "first change", "a.txt", "message", topic);
Result change2 = createChange(secondRepo, branch, "second change", "b.txt", "message", topic);
String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
Project.NameKey project1 = change1.getChange().project();
Project.NameKey project2 = change2.getChange().project();
try (Repository repository1 = repoManager.openRepository(project1);
Repository repository2 = repoManager.openRepository(project2)) {
ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
ObjectId originalDestinationBranchSha1Project1 = repository1.resolve(change1.getChange().change().getDest().branch());
ObjectId originalDestinationBranchSha1Project2 = repository2.resolve(change2.getChange().change().getDest().branch());
RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
String branchSha1Project1 = repository1.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
String branchSha1Project2 = repository2.getRefDatabase().exactRef(change2.getChange().change().getDest().branch()).getObjectId().name();
// During submit, all relevant meta refs of the latest patchset are updated + the destination
// branch/es.
// TODO(paiking): This doesn't work well for torn submissions: If the changes are in
// different projects in the same topic, and we tried to submit those changes together, it's
// possible that the first submission only submitted one of the changes, and then the retry
// submitted the other change. If that happens, when the user retries, they will not get the
// meta ref updates for the change that got submitted on the previous submission attempt.
// Ideally, submit should be idempotent and always return all meta refs on all submission
// attempts.
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(branch), originalDestinationBranchSha1Project1.getName(), branchSha1Project1), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(branch), originalDestinationBranchSha1Project2.getName(), branchSha1Project2));
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ChangeOperationsImplTest method createdChangeHasSpecifiedTargetBranch.
@Test
public void createdChangeHasSpecifiedTargetBranch() throws Exception {
Project.NameKey project = projectOperations.newProject().branches("test-branch").create();
Change.Id changeId = changeOperations.newChange().project(project).branch("test-branch").create();
ChangeInfo change = getChangeFromServer(changeId);
assertThat(change.branch).isEqualTo("test-branch");
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ChangeOperationsImplTest method createdChangeUsesSpecifiedBranchTipAsParent.
@Test
public void createdChangeUsesSpecifiedBranchTipAsParent() throws Exception {
Project.NameKey project = projectOperations.newProject().branches("test-branch").create();
Change.Id changeId = changeOperations.newChange().project(project).childOf().tipOfBranch("refs/heads/test-branch").create();
ChangeInfo change = getChangeFromServer(changeId);
CommitInfo currentPatchsetCommit = change.revisions.get(change.currentRevision).commit;
ObjectId parentCommitId = projectOperations.project(project).getHead("test-branch").getId();
assertThat(currentPatchsetCommit).parents().onlyElement().commit().isEqualTo(parentCommitId.name());
}
Aggregations