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();
}
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);
}
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);
}
Aggregations