Search in sources :

Example 6 with ListChangesOption

use of com.google.gerrit.extensions.client.ListChangesOption in project gerrit by GerritCodeReview.

the class ChangeIT method queryChangesOptions.

@Test
public void queryChangesOptions() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeInfo result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).get());
    assertThat(result.labels).isNull();
    assertThat(result.messages).isNull();
    assertThat(result.actions).isNull();
    assertThat(result.revisions).isNull();
    EnumSet<ListChangesOption> options = EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.CHANGE_ACTIONS, ListChangesOption.CURRENT_ACTIONS, ListChangesOption.DETAILED_LABELS, ListChangesOption.MESSAGES);
    result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOptions(options).get());
    assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo("Code-Review");
    assertThat(result.messages).hasSize(1);
    assertThat(result.actions).isNotEmpty();
    RevisionInfo rev = Iterables.getOnlyElement(result.revisions.values());
    assertThat(rev._number).isEqualTo(r.getPatchSetId().get());
    assertThat(rev.created).isNotNull();
    assertThat(rev.uploader._accountId).isEqualTo(admin.getId().get());
    assertThat(rev.ref).isEqualTo(r.getPatchSetId().toRefName());
    assertThat(rev.actions).isNotEmpty();
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) 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 7 with ListChangesOption

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

Example 8 with ListChangesOption

use of com.google.gerrit.extensions.client.ListChangesOption in project gerrit by GerritCodeReview.

the class ChangeScreen method loadChangeInfo.

void loadChangeInfo(boolean fg, AsyncCallback<ChangeInfo> cb) {
    RestApi call = ChangeApi.detail(changeId.get());
    EnumSet<ListChangesOption> opts = EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.CHANGE_ACTIONS);
    if (enableSignedPush()) {
        opts.add(ListChangesOption.PUSH_CERTIFICATES);
    }
    ChangeList.addOptions(call, opts);
    if (!fg) {
        call.background();
    }
    call.get(cb);
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) RestApi(com.google.gerrit.client.rpc.RestApi)

Aggregations

ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 Test (org.junit.Test)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 RestApi (com.google.gerrit.client.rpc.RestApi)1 LabelType (com.google.gerrit.common.data.LabelType)1 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)1 RegistrationHandle (com.google.gerrit.extensions.registration.RegistrationHandle)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 Branch (com.google.gerrit.reviewdb.client.Branch)1 Change (com.google.gerrit.reviewdb.client.Change)1 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)1