use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToSameBranchWithRebase.
@Test
public void cherryPickToSameBranchWithRebase() throws Exception {
// Push a new change, then merge it
PushOneCommit.Result baseChange = createChange();
String triplet = project.get() + "~master~" + baseChange.getChangeId();
RevisionApi baseRevision = gApi.changes().id(triplet).current();
baseRevision.review(ReviewInput.approve());
baseRevision.submit();
// Push a new change (change 1)
PushOneCommit.Result r1 = createChange();
// Push another new change (change 2)
String subject = "Test change\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, subject, "another_file.txt", "another content");
PushOneCommit.Result r2 = push.to("refs/for/master");
// Change 2's parent should be change 1
assertThat(r2.getCommit().getParents()[0].name()).isEqualTo(r1.getCommit().name());
// Cherry pick change 2 onto the same branch
triplet = project.get() + "~master~" + r2.getChangeId();
ChangeApi orig = gApi.changes().id(triplet);
CherryPickInput in = new CherryPickInput();
in.destination = "master";
in.message = subject;
ChangeApi cherry = orig.revision(r2.getCommit().name()).cherryPick(in);
ChangeInfo cherryInfo = cherry.get();
assertThat(cherryInfo.messages).hasSize(2);
Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
// Parent of change 2 should now be the change that was merged, i.e.
// change 2 is rebased onto the head of the master branch.
String newParent = cherryInfo.revisions.get(cherryInfo.currentRevision).commit.parents.get(0).commit;
assertThat(newParent).isEqualTo(baseChange.getCommit().name());
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickKeepReviewers.
@Test
public void cherryPickKeepReviewers() throws Exception {
createBranch(BranchNameKey.create(project, "stable"));
// Change is created by 'admin'.
PushOneCommit.Result r = createChange();
// Change is approved by 'admin2'. Change is CC'd to 'user'.
requestScopeOperations.setApiUser(accountCreator.admin2().id());
ReviewInput in = ReviewInput.approve();
in.reviewer(user.email(), ReviewerState.CC, true);
gApi.changes().id(r.getChangeId()).current().review(in);
// Change is cherrypicked by 'user2'.
requestScopeOperations.setApiUser(accountCreator.user2().id());
CherryPickInput cin = new CherryPickInput();
cin.message = "this need to go to stable";
cin.destination = "stable";
cin.keepReviewers = true;
Map<ReviewerState, Collection<AccountInfo>> result = gApi.changes().id(r.getChangeId()).current().cherryPick(cin).get().reviewers;
// 'admin' should be a reviewer as the old owner.
// 'admin2' should be a reviewer as the old reviewer.
// 'user' should be on CC.
assertThat(result).containsKey(ReviewerState.REVIEWER);
List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
assertThat(result).containsKey(ReviewerState.CC);
List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
assertThat(ccs).containsExactly(user.id().get());
assertThat(reviewers).containsExactly(admin.id().get(), accountCreator.admin2().id().get());
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickWorkInProgressChange.
@Test
public void cherryPickWorkInProgressChange() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master%wip");
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = "cherry pick message";
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().cherryPickOfChange).isEqualTo(orig.get()._number);
assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(1);
assertThat(cherry.get().workInProgress).isTrue();
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToSameBranch.
@Test
public void cherryPickToSameBranch() throws Exception {
PushOneCommit.Result r = createChange();
ChangeApi change = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
CherryPickInput in = new CherryPickInput();
in.destination = "master";
in.message = "it generates a new patch set\n\nChange-Id: " + r.getChangeId();
ChangeInfo cherryInfo = change.revision(r.getCommit().name()).cherryPick(in).get();
assertThat(cherryInfo.messages).hasSize(2);
Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
assertThat(cherryInfo.cherryPickOfChange).isEqualTo(change.get()._number);
// Existing change was updated.
assertThat(cherryInfo._number).isEqualTo(change.get()._number);
assertThat(cherryInfo.cherryPickOfPatchSet).isEqualTo(1);
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickWithValidationOptions.
@Test
public void cherryPickWithValidationOptions() throws Exception {
PushOneCommit.Result r = createChange();
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = "Cherry Pick";
in.validationOptions = ImmutableMap.of("key", "value");
gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
TestCommitValidationListener testCommitValidationListener = new TestCommitValidationListener();
try (Registration registration = extensionRegistry.newRegistration().add(testCommitValidationListener)) {
gApi.changes().id(r.getChangeId()).current().cherryPickAsInfo(in);
assertThat(testCommitValidationListener.receiveEvent.pushOptions).containsExactly("key", "value");
}
}
Aggregations