Search in sources :

Example 11 with RevisionInfo

use of com.google.gerrit.extensions.common.RevisionInfo 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)

Example 12 with RevisionInfo

use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithMessage.

@Test
public void pushForMasterWithMessage() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master/%m=my_test_message");
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, null);
    ChangeInfo ci = get(r.getChangeId());
    Collection<ChangeMessageInfo> changeMessages = ci.messages;
    assertThat(changeMessages).hasSize(1);
    for (ChangeMessageInfo cm : changeMessages) {
        assertThat(cm.message).isEqualTo("Uploaded patch set 1.\nmy test message");
    }
    Collection<RevisionInfo> revisions = ci.revisions.values();
    assertThat(revisions).hasSize(1);
    for (RevisionInfo ri : revisions) {
        assertThat(ri.description).isEqualTo("my test message");
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with RevisionInfo

use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithMessageTwiceWithDifferentMessages.

@Test
public void pushForMasterWithMessageTwiceWithDifferentMessages() throws Exception {
    enableCreateNewChangeForAllNotInTarget();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "a.txt", "content");
    PushOneCommit.Result r = push.to("refs/for/master/%m=my_test_message");
    r.assertOkStatus();
    push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent", r.getChangeId());
    r = push.to("refs/for/master/%m=new_test_message");
    r.assertOkStatus();
    ChangeInfo ci = get(r.getChangeId());
    Collection<RevisionInfo> revisions = ci.revisions.values();
    assertThat(revisions).hasSize(2);
    for (RevisionInfo ri : revisions) {
        if (ri.isCurrent) {
            assertThat(ri.description).isEqualTo("new test message");
        } else {
            assertThat(ri.description).isEqualTo("my test message");
        }
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with RevisionInfo

use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method changeActionVisitor.

@Test
public void changeActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS));
    class Visitor implements ActionVisitor {

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo) {
            assertThat(changeInfo).isNotNull();
            assertThat(changeInfo._number).isEqualTo(origChange._number);
            if (name.equals("followup")) {
                return false;
            }
            if (name.equals("abandon")) {
                actionInfo.label = "Abandon All Hope";
            }
            return true;
        }

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo, RevisionInfo revisionInfo) {
            throw new UnsupportedOperationException();
        }
    }
    Map<String, ActionInfo> origActions = origChange.actions;
    assertThat(origActions.keySet()).containsAllOf("followup", "abandon");
    assertThat(origActions.get("abandon").label).isEqualTo("Abandon");
    Visitor v = new Visitor();
    visitorHandle = actionVisitors.add(v);
    Map<String, ActionInfo> newActions = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)).actions;
    Set<String> expectedNames = new TreeSet<>(origActions.keySet());
    expectedNames.remove("followup");
    assertThat(newActions.keySet()).isEqualTo(expectedNames);
    ActionInfo abandon = newActions.get("abandon");
    assertThat(abandon).isNotNull();
    assertThat(abandon.label).isEqualTo("Abandon All Hope");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) TreeSet(java.util.TreeSet) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with RevisionInfo

use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method revisionActionVisitor.

@Test
public void revisionActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS));
    class Visitor implements ActionVisitor {

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo) {
            // Do nothing; implicitly called for CURRENT_ACTIONS.
            return true;
        }

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo, RevisionInfo revisionInfo) {
            assertThat(changeInfo).isNotNull();
            assertThat(changeInfo._number).isEqualTo(origChange._number);
            assertThat(revisionInfo).isNotNull();
            assertThat(revisionInfo._number).isEqualTo(1);
            if (name.equals("cherrypick")) {
                return false;
            }
            if (name.equals("rebase")) {
                actionInfo.label = "All Your Base";
            }
            return true;
        }
    }
    Map<String, ActionInfo> origActions = gApi.changes().id(id).current().actions();
    assertThat(origActions.keySet()).containsAllOf("cherrypick", "rebase");
    assertThat(origActions.get("rebase").label).isEqualTo("Rebase");
    Visitor v = new Visitor();
    visitorHandle = actionVisitors.add(v);
    // Test different codepaths within ActionJson...
    // ...via revision API.
    visitedRevisionActionsAssertions(origActions, gApi.changes().id(id).current().actions());
    // ...via change API with option.
    EnumSet<ListChangesOption> opts = EnumSet.of(CURRENT_ACTIONS, CURRENT_REVISION);
    ChangeInfo changeInfo = gApi.changes().id(id).get(opts);
    RevisionInfo revisionInfo = Iterables.getOnlyElement(changeInfo.revisions.values());
    visitedRevisionActionsAssertions(origActions, revisionInfo.actions);
    // ...via ChangeJson directly.
    ChangeData cd = changeDataFactory.create(db, project, new Change.Id(origChange._number));
    revisionInfo = changeJsonFactory.create(opts).getRevisionInfo(cd.changeControl(), Iterables.getOnlyElement(cd.patchSets()));
    visitedRevisionActionsAssertions(origActions, revisionInfo.actions);
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)13 Test (org.junit.Test)13 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)3 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)3 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)3 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)3 Change (com.google.gerrit.reviewdb.client.Change)3 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)2 SubmittedTogetherInfo (com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo)2 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)2 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GerritConfig (com.google.gerrit.acceptance.GerritConfig)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 SubmitTypeRecord (com.google.gerrit.common.data.SubmitTypeRecord)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1