Search in sources :

Example 11 with ChangeApi

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

the class ChangeIdIT method changeIdReturnsChange.

@Test
public void changeIdReturnsChange() throws Exception {
    // ChangeId is not unique and this method needs a unique changeId to work.
    // Hence we generate a new change with a different content.
    ChangeInfo ci = gApi.changes().create(new ChangeInput(project.get(), "master", "different message")).get();
    ChangeApi cApi = gApi.changes().id(ci.changeId);
    assertThat(cApi.get()._number).isEqualTo(ci._number);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with ChangeApi

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

the class RevisionIT method cherryPickIdenticalTree.

@Test
public void cherryPickIdenticalTree() throws Exception {
    PushOneCommit.Result r = createChange();
    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);
    ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
    Collection<ChangeMessageInfo> messages = gApi.changes().id(project.get() + "~master~" + r.getChangeId()).get().messages;
    assertThat(messages).hasSize(2);
    assertThat(cherry.get().subject).contains(in.message);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
    exception.expect(ResourceConflictException.class);
    exception.expectMessage("Cherry pick failed: identical tree");
    orig.revision(r.getCommit().name()).cherryPick(in);
}
Also used : 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 13 with ChangeApi

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

the class RevisionIT method cherryPickConflict.

@Test
public void cherryPickConflict() throws Exception {
    PushOneCommit.Result r = createChange();
    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());
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, "another content");
    push.to("refs/heads/foo");
    String triplet = project.get() + "~master~" + r.getChangeId();
    ChangeApi orig = gApi.changes().id(triplet);
    assertThat(orig.get().messages).hasSize(1);
    exception.expect(ResourceConflictException.class);
    exception.expectMessage("Cherry pick failed: merge conflict");
    orig.revision(r.getCommit().name()).cherryPick(in);
}
Also used : ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) 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 14 with ChangeApi

use of com.google.gerrit.extensions.api.changes.ChangeApi 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);
    ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
    Collection<ChangeMessageInfo> messages = gApi.changes().id(project.get() + "~master~" + r.getChangeId()).get().messages;
    assertThat(messages).hasSize(2);
    String cherryPickedRevision = cherry.get().currentRevision;
    String expectedMessage = String.format("Patch Set 1: Cherry Picked\n\n" + "This patchset was cherry picked to branch %s as commit %s", in.destination, cherryPickedRevision);
    Iterator<ChangeMessageInfo> origIt = messages.iterator();
    origIt.next();
    assertThat(origIt.next().message).isEqualTo(expectedMessage);
    assertThat(cherry.get().messages).hasSize(1);
    Iterator<ChangeMessageInfo> cherryIt = cherry.get().messages.iterator();
    expectedMessage = "Patch Set 1: Cherry Picked from branch master.";
    assertThat(cherryIt.next().message).isEqualTo(expectedMessage);
    assertThat(cherry.get().subject).contains(in.message);
    assertThat(cherry.get().topic).isEqualTo("someTopic-foo");
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
}
Also used : 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 15 with ChangeApi

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

the class RevisionIT method cherryPickSetChangeId.

@Test
public void cherryPickSetChangeId() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master");
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    String id = "Ideadbeefdeadbeefdeadbeefdeadbeefdeadbe3f";
    in.message = "it goes to foo branch\n\nChange-Id: " + id;
    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);
    ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
    ChangeInfo changeInfo = cherry.get();
    // The cherry-pick honors the ChangeId specified in the input message:
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).endsWith(id + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)17 Test (org.junit.Test)17 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)12 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)10 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 RefSpec (org.eclipse.jgit.transport.RefSpec)4 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)3 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)2 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Result (com.google.gerrit.acceptance.PushOneCommit.Result)1 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)1 Project (com.google.gerrit.reviewdb.client.Project)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1