use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToExistingMergedChange.
@Test
public void cherryPickToExistingMergedChange() throws Exception {
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "a").to("refs/for/master");
BranchInput bin = new BranchInput();
bin.revision = r1.getCommit().getParent(0).name();
gApi.projects().name(project.get()).branch("foo").create(bin);
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "b", r1.getChangeId()).to("refs/for/foo");
String t2 = project.get() + "~foo~" + r2.getChangeId();
gApi.changes().id(t2).current().review(ReviewInput.approve());
gApi.changes().id(t2).current().submit();
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = r1.getCommit().getFullMessage();
in.allowConflicts = true;
in.allowEmpty = true;
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(t2).current().cherryPick(in));
assertThat(thrown).hasMessageThat().isEqualTo(String.format("Cherry-pick with Change-Id %s could not update the existing change %d in " + "destination branch refs/heads/foo of project %s, because " + "the change was closed (MERGED)", r1.getChangeId(), info(t2)._number, project.get()));
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickWithoutMessage.
@Test
public void cherryPickWithoutMessage() throws Exception {
String branch = "foo";
// Create change to cherry-pick
PushOneCommit.Result change = createChange();
RevCommit revCommit = change.getCommit();
// Create target branch to cherry-pick to.
gApi.projects().name(project.get()).branch(branch).create(new BranchInput());
// Cherry-pick without message.
CherryPickInput input = new CherryPickInput();
input.destination = branch;
String changeId = gApi.changes().id(change.getChangeId()).revision(revCommit.name()).cherryPickAsInfo(input).id;
// Expect that the message of the cherry-picked commit was used for the cherry-pick change.
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(revCommit.getFullMessage());
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickSetsReadyChangeOnNewPatchset.
@Test
@UseClockStep
public void cherryPickSetsReadyChangeOnNewPatchset() throws Exception {
PushOneCommit.Result result = pushTo("refs/for/master");
CherryPickInput input = new CherryPickInput();
input.destination = "foo";
gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
ChangeApi originalChange = gApi.changes().id(project.get() + "~master~" + result.getChangeId());
ChangeApi cherryPick = originalChange.revision(result.getCommit().name()).cherryPick(input);
String firstCherryPickChangeId = cherryPick.id();
cherryPick.setWorkInProgress();
gApi.changes().id(project.get() + "~master~" + result.getChangeId()).revision(result.getCommit().name()).cherryPick(input);
ChangeInfo secondCherryPickResult = gApi.changes().id(firstCherryPickChangeId).get(ALL_REVISIONS);
assertThat(secondCherryPickResult.revisions).hasSize(2);
assertThat(secondCherryPickResult.workInProgress).isNull();
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickNotify.
@Test
public void cherryPickNotify() throws Exception {
createBranch(BranchNameKey.create(project, "branch-1"));
createBranch(BranchNameKey.create(project, "branch-2"));
createBranch(BranchNameKey.create(project, "branch-3"));
// Creates a change for 'admin'.
PushOneCommit.Result result = createChange();
String changeId = project.get() + "~master~" + result.getChangeId();
// 'user' cherry-picks the change to a new branch, the source change's author/committer('admin')
// will be added as cc of the newly created change.
requestScopeOperations.setApiUser(user.id());
CherryPickInput input = new CherryPickInput();
input.message = "it goes to a new branch";
// Enable the notification. 'admin' as a reviewer should be notified.
input.destination = "branch-1";
input.notify = NotifyHandling.ALL;
sender.clear();
gApi.changes().id(changeId).current().cherryPick(input);
assertNotifyCc(admin);
// Disable the notification. 'admin' as a reviewer should not be notified any more.
input.destination = "branch-2";
input.notify = NotifyHandling.NONE;
sender.clear();
gApi.changes().id(changeId).current().cherryPick(input);
assertThat(sender.getMessages()).isEmpty();
// Disable the notification. The user provided in the 'notifyDetails' should still be notified.
TestAccount userToNotify = accountCreator.user2();
input.destination = "branch-3";
input.notify = NotifyHandling.NONE;
input.notifyDetails = ImmutableMap.of(RecipientType.TO, new NotifyInfo(ImmutableList.of(userToNotify.email())));
sender.clear();
gApi.changes().id(changeId).current().cherryPick(input);
assertNotifyTo(userToNotify);
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method getRelatedCherryPicks.
@Test
public void getRelatedCherryPicks() throws Exception {
PushOneCommit.Result r1 = createChange(SUBJECT, "a.txt", "a");
PushOneCommit.Result r2 = createChange(SUBJECT, "b.txt", "b");
String branch = "foo";
// Create target branch to cherry-pick to.
gApi.projects().name(project.get()).branch(branch).create(new BranchInput());
CherryPickInput input = new CherryPickInput();
input.message = "message";
input.destination = branch;
ChangeInfo firstCherryPickResult = gApi.changes().id(r1.getChangeId()).current().cherryPickAsInfo(input);
input.base = gApi.changes().id(firstCherryPickResult.changeId).current().commit(false).commit;
ChangeInfo secondCherryPickResult = gApi.changes().id(r2.getChangeId()).current().cherryPickAsInfo(input);
assertThat(gApi.changes().id(firstCherryPickResult.changeId).current().related().changes).hasSize(2);
assertThat(gApi.changes().id(secondCherryPickResult.changeId).current().related().changes).hasSize(2);
}
Aggregations