Search in sources :

Example 46 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickToNonVisibleChangeFails.

@Test
public void cherryPickToNonVisibleChangeFails() throws Exception {
    createBranch(BranchNameKey.create(project, "foo"));
    PushOneCommit.Result dstChange = createChange(testRepo, "foo", SUBJECT, "b.txt", "b", "t");
    dstChange.assertOkStatus();
    gApi.changes().id(dstChange.getChangeId()).setPrivate(true, null);
    PushOneCommit.Result srcChange = createChange();
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    input.base = dstChange.getCommit().name();
    input.message = srcChange.getCommit().getFullMessage();
    requestScopeOperations.setApiUser(user.id());
    UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.changes().id(srcChange.getChangeId()).current().cherryPick(input).get());
    assertThat(thrown).hasMessageThat().contains(String.format("Commit %s does not exist on branch refs/heads/foo", input.base));
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 47 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickToOpenChangeRevision.

@Test
public void cherryPickToOpenChangeRevision() throws Exception {
    createBranch(BranchNameKey.create(project, "foo"));
    PushOneCommit.Result dstChange = createChange(testRepo, "foo", SUBJECT, "b.txt", "b", "t");
    dstChange.assertOkStatus();
    PushOneCommit.Result srcChange = createChange();
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    input.base = dstChange.getCommit().name();
    input.message = srcChange.getCommit().getFullMessage();
    ChangeInfo changeInfo = gApi.changes().id(srcChange.getChangeId()).current().cherryPick(input).get();
    assertCherryPickResult(changeInfo, input, srcChange.getChangeId());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 48 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickToAbandonedChangeFails.

@Test
public void cherryPickToAbandonedChangeFails() throws Exception {
    PushOneCommit.Result change1 = createChange();
    PushOneCommit.Result change2 = createChange();
    gApi.changes().id(change2.getChangeId()).abandon();
    CherryPickInput input = new CherryPickInput();
    input.destination = "master";
    input.base = change2.getCommit().name();
    input.message = change1.getCommit().getFullMessage();
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(change1.getChangeId()).current().cherryPick(input));
    assertThat(thrown).hasMessageThat().contains(String.format("Change %s with commit %s is abandoned", change2.getChange().getId().get(), input.base));
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 49 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPick.

@Test
public void cherryPick() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master%topic=someTopic");
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    in.message = "it goes to stable branch";
    gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
    ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
    assertThat(orig.get().messages).hasSize(1);
    ChangeInfo changeInfo = orig.revision(r.getCommit().name()).cherryPickAsInfo(in);
    assertThat(changeInfo.containsGitConflicts).isNull();
    assertThat(changeInfo.workInProgress).isNull();
    ChangeApi cherry = gApi.changes().id(changeInfo._number);
    ChangeInfo cherryPickChangeInfoWithDetails = cherry.get();
    assertThat(cherryPickChangeInfoWithDetails.workInProgress).isNull();
    assertThat(cherryPickChangeInfoWithDetails.messages).hasSize(1);
    Iterator<ChangeMessageInfo> cherryIt = cherryPickChangeInfoWithDetails.messages.iterator();
    assertThat(cherryIt.next().message).isEqualTo("Patch Set 1: Cherry Picked from branch master.");
    assertThat(cherry.get().subject).contains(in.message);
    assertThat(cherry.get().topic).isEqualTo("someTopic-foo");
    assertThat(cherry.get().cherryPickOfChange).isEqualTo(orig.get()._number);
    assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(1);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 50 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickToNonExistingBaseCommit.

@Test
public void cherryPickToNonExistingBaseCommit() throws Exception {
    createBranch(BranchNameKey.create(project, "foo"));
    PushOneCommit.Result result = createChange();
    CherryPickInput input = new CherryPickInput();
    input.message = "foo bar";
    input.destination = "foo";
    input.base = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
    UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.changes().id(result.getChangeId()).current().cherryPick(input));
    assertThat(thrown).hasMessageThat().isEqualTo(String.format("Base %s doesn't exist", input.base));
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)57 Test (org.junit.Test)53 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)50 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)49 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)27 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)11 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)11 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 Result (com.google.gerrit.acceptance.PushOneCommit.Result)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 RefSpec (org.eclipse.jgit.transport.RefSpec)5 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)3 FileInfo (com.google.gerrit.extensions.common.FileInfo)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 Iterables (com.google.common.collect.Iterables)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2