Search in sources :

Example 36 with RevisionInfo

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

the class SubmittedTogetherIT method doesNotIncludeCurrentFiles.

@Test
public void doesNotIncludeCurrentFiles() throws Exception {
    RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
    RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create();
    String id2 = getChangeId(c2_1);
    pushHead(testRepo, "refs/for/master", false);
    SubmittedTogetherInfo info = gApi.changes().id(id2).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
    assertThat(info.changes).hasSize(2);
    assertThat(info.changes.get(0).currentRevision).isEqualTo(c2_1.name());
    assertThat(info.changes.get(1).currentRevision).isEqualTo(c1_1.name());
    RevisionInfo rev = info.changes.get(0).revisions.get(c2_1.name());
    assertThat(rev.files).isNull();
}
Also used : RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with RevisionInfo

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

the class ActionsIT method currentRevisionActionVisitor.

@Test
public void currentRevisionActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    amendChange(id);
    ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
    Change.Id changeId = Change.id(origChange._number);
    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(2);
            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()).containsAtLeast("cherrypick", "rebase");
    assertThat(origActions.get("rebase").label).isEqualTo("Rebase");
    try (Registration registration = extensionRegistry.newRegistration().add(new Visitor())) {
        // Test different codepaths within ActionJson...
        // ...via revision API.
        visitedCurrentRevisionActionsAssertions(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());
        visitedCurrentRevisionActionsAssertions(origActions, revisionInfo.actions);
        // ...via ChangeJson directly.
        ChangeData cd = changeDataFactory.create(project, changeId);
        revisionJsonFactory.create(opts).getRevisionInfo(cd, cd.patchSet(PatchSet.id(changeId, 1)));
    }
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) 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.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 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(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()).containsAtLeast("followup", "abandon");
    assertThat(origActions.get("abandon").label).isEqualTo("Abandon");
    try (Registration registration = extensionRegistry.newRegistration().add(new Visitor())) {
        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) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) 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 39 with RevisionInfo

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

the class ChangeOperationsImplTest method newPatchsetCanBeCreatedWithoutSpecifyingAnyParameters.

@Test
public void newPatchsetCanBeCreatedWithoutSpecifyingAnyParameters() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    ChangeInfo unmodifiedChange = getChangeFromServer(changeId);
    int originalPatchsetCount = unmodifiedChange.revisions.size();
    PatchSet.Id patchsetId = changeOperations.change(changeId).newPatchset().create();
    ChangeInfo change = getChangeFromServer(changeId);
    assertThatMap(change.revisions).hasSize(originalPatchsetCount + 1);
    RevisionInfo currentRevision = change.revisions.get(change.currentRevision);
    assertThat(currentRevision._number).isEqualTo(patchsetId.get());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)39 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)29 Test (org.junit.Test)29 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)13 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)10 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)10 Change (com.google.gerrit.entities.Change)8 Result (com.google.gerrit.acceptance.PushOneCommit.Result)5 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)5 PatchSet (com.google.gerrit.entities.PatchSet)4 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)4 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)3 RebaseInput (com.google.gerrit.extensions.api.changes.RebaseInput)3 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)3 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)3 Change (com.google.gerrit.reviewdb.client.Change)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 Repository (org.eclipse.jgit.lib.Repository)3