use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickWithSetTopic.
@Test
public void cherryPickWithSetTopic() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.topic = "topic";
gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
assertThat(cherry.get().topic).isEqualTo("topic");
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevertSubmission method revertSubmission.
private RevertSubmissionInfo revertSubmission(List<ChangeData> changeData, RevertInput revertInput) throws RestApiException, IOException, UpdateException, ConfigInvalidException, StorageException, PermissionBackendException {
Multimap<BranchNameKey, ChangeData> changesPerProjectAndBranch = ArrayListMultimap.create();
changeData.stream().forEach(c -> changesPerProjectAndBranch.put(c.change().getDest(), c));
cherryPickInput = createCherryPickInput(revertInput);
Instant timestamp = TimeUtil.now();
for (BranchNameKey projectAndBranch : changesPerProjectAndBranch.keySet()) {
cherryPickInput.base = null;
Project.NameKey project = projectAndBranch.project();
cherryPickInput.destination = projectAndBranch.branch();
if (revertInput.workInProgress) {
cherryPickInput.notify = firstNonNull(cherryPickInput.notify, NotifyHandling.OWNER);
}
Collection<ChangeData> changesInProjectAndBranch = changesPerProjectAndBranch.get(projectAndBranch);
// Sort the changes topologically.
Iterator<PatchSetData> sortedChangesInProjectAndBranch = sorter.sort(changesInProjectAndBranch).iterator();
Set<ObjectId> commitIdsInProjectAndBranch = changesInProjectAndBranch.stream().map(c -> c.currentPatchSet().commitId()).collect(Collectors.toSet());
revertAllChangesInProjectAndBranch(revertInput, project, sortedChangesInProjectAndBranch, commitIdsInProjectAndBranch, timestamp);
}
results.sort(Comparator.comparing(c -> c.revertOf));
RevertSubmissionInfo revertSubmissionInfo = new RevertSubmissionInfo();
revertSubmissionInfo.revertChanges = results;
return revertSubmissionInfo;
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
List<String> footers = commitToCherryPick.getFooterLines("Change-Id");
assertThat(footers).hasSize(1);
String changeId = footers.get(0);
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef\n\nChange-Id: %s\n", changeId);
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
// No change was found in destination branch with the provided Change-Id.
assertThat(cherryPickResult._number).isGreaterThan(changeToCherryPick._number);
assertThat(cherryPickResult.changeId).isEqualTo(changeId);
assertThat(cherryPickResult.revisions).hasSize(1);
assertThat(cherryPickResult.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", commitToCherryPick.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
// Cherry-pick of is not set, because the source change was not provided.
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitToExistingCherryPickedChange.
@Test
public void cherryPickCommitToExistingCherryPickedChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange("refs/for/" + destBranch);
ChangeInfo existingDestChange = info(r.getChangeId());
r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: %s\n", existingDestChange.changeId);
input.allowConflicts = true;
input.allowEmpty = true;
// Use RevisionAPI to submit initial cherryPick.
ChangeInfo cherryPickResult = gApi.changes().id(changeToCherryPick.changeId).current().cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
// Cherry-pick was set.
assertThat(cherryPickResult.cherryPickOfChange).isEqualTo(changeToCherryPick._number);
assertThat(cherryPickResult.cherryPickOfPatchSet).isEqualTo(1);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
// Use CommitApi to update the cherryPick change.
cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
assertThat(cherryPickResult.messages).hasSize(3);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 2.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 3.");
// Cherry-pick was reset to empty value.
assertThat(cherryPickResult._number).isEqualTo(existingDestChange._number);
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithoutChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithoutChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = "it goes to foo branch";
RevCommit commitToCherryPick = createNewCommitWithoutChangeId("refs/heads/master", "a.txt", "content");
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", commitToCherryPick.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
CommitInfo commitInfo = revInfo.commit;
assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + cherryPickResult.changeId + "\n");
}
Aggregations