Merge "ChangeApi: Add convenience overrides for get with options"

This commit is contained in:
Alice Kober-Sotzek
2017-09-13 13:10:29 +00:00
committed by Gerrit Code Review
11 changed files with 80 additions and 122 deletions

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume; import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.acceptance.GitUtil.initSsh; import static com.google.gerrit.acceptance.GitUtil.initSsh;
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES; import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG; import static com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG;
import static com.google.gerrit.reviewdb.client.Patch.MERGE_LIST; import static com.google.gerrit.reviewdb.client.Patch.MERGE_LIST;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -30,7 +31,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.jimfs.Jimfs; import com.google.common.jimfs.Jimfs;
import com.google.common.primitives.Chars; import com.google.common.primitives.Chars;
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context; import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
@@ -644,11 +644,7 @@ public abstract class AbstractDaemonTest {
private List<Boolean> getPatchSetDraftStatuses(Change.Id id) throws Exception { private List<Boolean> getPatchSetDraftStatuses(Change.Id id) throws Exception {
Collection<RevisionInfo> revisionInfos = Collection<RevisionInfo> revisionInfos =
gApi.changes() gApi.changes().id(id.get()).get(ALL_REVISIONS).revisions.values();
.id(id.get())
.get(EnumSet.of(ListChangesOption.ALL_REVISIONS))
.revisions
.values();
return revisionInfos.stream().map(revisionInfo -> revisionInfo.draft).collect(toList()); return revisionInfos.stream().map(revisionInfo -> revisionInfo.draft).collect(toList());
} }
@@ -805,9 +801,7 @@ public abstract class AbstractDaemonTest {
} }
protected ChangeInfo get(String id, ListChangesOption... options) throws RestApiException { protected ChangeInfo get(String id, ListChangesOption... options) throws RestApiException {
return gApi.changes() return gApi.changes().id(id).get(options);
.id(id)
.get(Sets.newEnumSet(Arrays.asList(options), ListChangesOption.class));
} }
protected List<ChangeInfo> query(String q) throws RestApiException { protected List<ChangeInfo> query(String q) throws RestApiException {

View File

@@ -22,6 +22,20 @@ import static com.google.gerrit.acceptance.GitUtil.pushHead;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT; import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME; import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import static com.google.gerrit.acceptance.PushOneCommit.SUBJECT; import static com.google.gerrit.acceptance.PushOneCommit.SUBJECT;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CHECK;
import static com.google.gerrit.extensions.client.ListChangesOption.COMMIT_FOOTERS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import static com.google.gerrit.extensions.client.ListChangesOption.LABELS;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFICATES;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWED;
import static com.google.gerrit.extensions.client.ListChangesOption.TRACKING_IDS;
import static com.google.gerrit.extensions.client.ReviewerState.CC; import static com.google.gerrit.extensions.client.ReviewerState.CC;
import static com.google.gerrit.extensions.client.ReviewerState.REMOVED; import static com.google.gerrit.extensions.client.ReviewerState.REMOVED;
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER; import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
@@ -74,7 +88,6 @@ import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ChangeStatus; import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.Comment.Range; import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.InheritableBoolean; import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState; import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.Side; import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.client.SubmitType; import com.google.gerrit.extensions.client.SubmitType;
@@ -129,7 +142,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -703,17 +715,11 @@ public class ChangeIT extends AbstractDaemonTest {
rebase.call(changeId); rebase.call(changeId);
// Second change should have 2 patch sets and an approval // Second change should have 2 patch sets and an approval
ChangeInfo c2 = ChangeInfo c2 = gApi.changes().id(changeId).get(CURRENT_REVISION, DETAILED_LABELS);
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.CURRENT_REVISION, ListChangesOption.DETAILED_LABELS));
assertThat(c2.revisions.get(c2.currentRevision)._number).isEqualTo(2); assertThat(c2.revisions.get(c2.currentRevision)._number).isEqualTo(2);
// ...and the committer and description should be correct // ...and the committer and description should be correct
ChangeInfo info = ChangeInfo info = gApi.changes().id(changeId).get(CURRENT_REVISION, CURRENT_COMMIT);
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.CURRENT_REVISION, ListChangesOption.CURRENT_COMMIT));
GitPerson committer = info.revisions.get(info.currentRevision).commit.committer; GitPerson committer = info.revisions.get(info.currentRevision).commit.committer;
assertThat(committer.name).isEqualTo(admin.fullName); assertThat(committer.name).isEqualTo(admin.fullName);
assertThat(committer.email).isEqualTo(admin.email); assertThat(committer.email).isEqualTo(admin.email);
@@ -2059,15 +2065,13 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(result.actions).isNull(); assertThat(result.actions).isNull();
assertThat(result.revisions).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 = result =
Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOptions(options).get()); Iterables.getOnlyElement(
gApi.changes()
.query(r.getChangeId())
.withOptions(
ALL_REVISIONS, CHANGE_ACTIONS, CURRENT_ACTIONS, DETAILED_LABELS, MESSAGES)
.get());
assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo("Code-Review"); assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo("Code-Review");
assertThat(result.messages).hasSize(1); assertThat(result.messages).hasSize(1);
assertThat(result.actions).isNotEmpty(); assertThat(result.actions).isNotEmpty();
@@ -2193,8 +2197,7 @@ public class ChangeIT extends AbstractDaemonTest {
public void check() throws Exception { public void check() throws Exception {
PushOneCommit.Result r = createChange(); PushOneCommit.Result r = createChange();
assertThat(gApi.changes().id(r.getChangeId()).get().problems).isNull(); assertThat(gApi.changes().id(r.getChangeId()).get().problems).isNull();
assertThat(gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.CHECK)).problems) assertThat(gApi.changes().id(r.getChangeId()).get(CHECK).problems).isEmpty();
.isEmpty();
} }
@Test @Test
@@ -2232,9 +2235,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.label("Custom2", 1); in.label("Custom2", 1);
gApi.changes().id(r2.getChangeId()).current().review(in); gApi.changes().id(r2.getChangeId()).current().review(in);
EnumSet<ListChangesOption> options = ChangeInfo actual = gApi.changes().id(r2.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.COMMIT_FOOTERS);
ChangeInfo actual = gApi.changes().id(r2.getChangeId()).get(options);
assertThat(actual.revisions).hasSize(2); assertThat(actual.revisions).hasSize(2);
// No footers except on latest patch set. // No footers except on latest patch set.
@@ -2277,9 +2278,7 @@ public class ChangeIT extends AbstractDaemonTest {
}); });
ChangeInfo actual; ChangeInfo actual;
try { try {
EnumSet<ListChangesOption> options = actual = gApi.changes().id(change.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.COMMIT_FOOTERS);
actual = gApi.changes().id(change.getChangeId()).get(options);
} finally { } finally {
handle.remove(); handle.remove();
} }
@@ -2320,9 +2319,9 @@ public class ChangeIT extends AbstractDaemonTest {
.query() .query()
.withQuery("project:{" + project.get() + "} (status:open OR status:closed)") .withQuery("project:{" + project.get() + "} (status:open OR status:closed)")
// Options should match defaults in AccountDashboardScreen. // Options should match defaults in AccountDashboardScreen.
.withOption(ListChangesOption.LABELS) .withOption(LABELS)
.withOption(ListChangesOption.DETAILED_ACCOUNTS) .withOption(DETAILED_ACCOUNTS)
.withOption(ListChangesOption.REVIEWED) .withOption(REVIEWED)
.get()) .get())
.hasSize(2); .hasSize(2);
} finally { } finally {
@@ -2335,7 +2334,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange(); PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId(); String triplet = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(triplet).addReviewer(user.username); gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review"); LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1); assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0); ApprovalInfo approval = codeReview.all.get(0);
@@ -2345,7 +2344,7 @@ public class ChangeIT extends AbstractDaemonTest {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig(); ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
Util.blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*"); Util.blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*");
saveProjectConfig(project, cfg); saveProjectConfig(project, cfg);
c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); c = gApi.changes().id(triplet).get(DETAILED_LABELS);
codeReview = c.labels.get("Code-Review"); codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1); assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0); approval = codeReview.all.get(0);
@@ -2360,10 +2359,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r1 = createChange(); PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = amendChange(r1.getChangeId()); PushOneCommit.Result r2 = amendChange(r1.getChangeId());
ChangeInfo info = ChangeInfo info = gApi.changes().id(r1.getChangeId()).get(ALL_REVISIONS, PUSH_CERTIFICATES);
gApi.changes()
.id(r1.getChangeId())
.get(EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.PUSH_CERTIFICATES));
RevisionInfo rev1 = info.revisions.get(r1.getCommit().name()); RevisionInfo rev1 = info.revisions.get(r1.getCommit().name());
assertThat(rev1).isNotNull(); assertThat(rev1).isNotNull();
@@ -2675,13 +2671,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.subject = "update change by merge ps2"; in.subject = "update change by merge ps2";
gApi.changes().id(changeId).createMergePatchSet(in); gApi.changes().id(changeId).createMergePatchSet(in);
ChangeInfo changeInfo = ChangeInfo changeInfo =
gApi.changes() gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
assertThat(changeInfo.revisions.size()).isEqualTo(2); assertThat(changeInfo.revisions.size()).isEqualTo(2);
assertThat(changeInfo.subject).isEqualTo(in.subject); assertThat(changeInfo.subject).isEqualTo(in.subject);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit) assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit)
@@ -2718,13 +2708,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.inheritParent = true; in.inheritParent = true;
gApi.changes().id(changeId).createMergePatchSet(in); gApi.changes().id(changeId).createMergePatchSet(in);
ChangeInfo changeInfo = ChangeInfo changeInfo =
gApi.changes() gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
assertThat(changeInfo.revisions.size()).isEqualTo(2); assertThat(changeInfo.revisions.size()).isEqualTo(2);
assertThat(changeInfo.subject).isEqualTo(in.subject); assertThat(changeInfo.subject).isEqualTo(in.subject);
@@ -2930,7 +2914,7 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(triplet).addReviewer(user.username); gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review"); LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1); assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0); ApprovalInfo approval = codeReview.all.get(0);
@@ -2950,7 +2934,7 @@ public class ChangeIT extends AbstractDaemonTest {
heads); heads);
saveProjectConfig(project, cfg); saveProjectConfig(project, cfg);
c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); c = gApi.changes().id(triplet).get(DETAILED_LABELS);
codeReview = c.labels.get("Code-Review"); codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1); assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0); approval = codeReview.all.get(0);
@@ -2971,7 +2955,7 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(triplet).addReviewer(user.username); gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review"); LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1); assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0); ApprovalInfo approval = codeReview.all.get(0);
@@ -3155,14 +3139,7 @@ public class ChangeIT extends AbstractDaemonTest {
ri.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(ci)); ri.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(ci));
gApi.changes().id(id).current().review(ri); gApi.changes().id(id).current().review(ri);
ChangeInfo info = ChangeInfo info = gApi.changes().id(id).get(MESSAGES, CURRENT_COMMIT, CURRENT_REVISION);
gApi.changes()
.id(id)
.get(
EnumSet.of(
ListChangesOption.MESSAGES,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
assertThat(info.subject).isEqualTo(subject); assertThat(info.subject).isEqualTo(subject);
assertThat(Iterables.getLast(info.messages).message).endsWith(ri.message); assertThat(Iterables.getLast(info.messages).message).endsWith(ri.message);
assertThat(Iterables.getOnlyElement(info.revisions.values()).commit.message) assertThat(Iterables.getOnlyElement(info.revisions.values()).commit.message)
@@ -3308,7 +3285,7 @@ public class ChangeIT extends AbstractDaemonTest {
private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId) private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId)
throws Exception { throws Exception {
ChangeInfo c = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)); ChangeInfo c = gApi.changes().id(changeId).get(DETAILED_LABELS);
Set<ReviewerState> states = Set<ReviewerState> states =
c.reviewers c.reviewers
.entrySet() .entrySet()
@@ -3369,8 +3346,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result result = push.to("refs/for/master"); PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus(); result.assertOkStatus();
ChangeInfo change = ChangeInfo change = gApi.changes().id(result.getChangeId()).get(TRACKING_IDS);
gApi.changes().id(result.getChangeId()).get(EnumSet.of(ListChangesOption.TRACKING_IDS));
Collection<TrackingIdInfo> trackingIds = change.trackingIds; Collection<TrackingIdInfo> trackingIds = change.trackingIds;
assertThat(trackingIds).isNotNull(); assertThat(trackingIds).isNotNull();
assertThat(trackingIds).hasSize(1); assertThat(trackingIds).hasSize(1);

View File

@@ -20,6 +20,9 @@ import static com.google.gerrit.extensions.client.ChangeKind.NO_CHANGE;
import static com.google.gerrit.extensions.client.ChangeKind.NO_CODE_CHANGE; import static com.google.gerrit.extensions.client.ChangeKind.NO_CODE_CHANGE;
import static com.google.gerrit.extensions.client.ChangeKind.REWORK; import static com.google.gerrit.extensions.client.ChangeKind.REWORK;
import static com.google.gerrit.extensions.client.ChangeKind.TRIVIAL_REBASE; import static com.google.gerrit.extensions.client.ChangeKind.TRIVIAL_REBASE;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
import static com.google.gerrit.server.project.Util.category; import static com.google.gerrit.server.project.Util.category;
import static com.google.gerrit.server.project.Util.value; import static com.google.gerrit.server.project.Util.value;
@@ -38,7 +41,6 @@ import com.google.gerrit.extensions.api.changes.CherryPickInput;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.RevisionApi; import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.client.ChangeKind; import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ApprovalInfo; import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.CommitInfo; import com.google.gerrit.extensions.common.CommitInfo;
@@ -336,13 +338,7 @@ public class StickyApprovalsIT extends AbstractDaemonTest {
} }
private ChangeInfo detailedChange(String changeId) throws Exception { private ChangeInfo detailedChange(String changeId) throws Exception {
return gApi.changes() return gApi.changes().id(changeId).get(DETAILED_LABELS, CURRENT_REVISION, CURRENT_COMMIT);
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.DETAILED_LABELS,
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT));
} }
private void assertNotSticky(Set<ChangeKind> changeKinds) throws Exception { private void assertNotSticky(Set<ChangeKind> changeKinds) throws Exception {
@@ -533,7 +529,7 @@ public class StickyApprovalsIT extends AbstractDaemonTest {
} }
private ChangeKind getChangeKind(String changeId) throws Exception { private ChangeKind getChangeKind(String changeId) throws Exception {
ChangeInfo c = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.CURRENT_REVISION)); ChangeInfo c = gApi.changes().id(changeId).get(CURRENT_REVISION);
return c.revisions.get(c.currentRevision).kind; return c.revisions.get(c.currentRevision).kind;
} }

View File

@@ -53,7 +53,6 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
import com.google.gerrit.extensions.api.changes.RevisionApi; import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.BranchInput; import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.client.ChangeStatus; import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState; import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.SubmitType; import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.AccountInfo; import com.google.gerrit.extensions.common.AccountInfo;
@@ -92,7 +91,6 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -162,8 +160,7 @@ public class RevisionIT extends AbstractDaemonTest {
approval = getApproval(changeId, label); approval = getApproval(changeId, label);
assertThat(approval.value).isEqualTo(1); assertThat(approval.value).isEqualTo(1);
assertThat(approval.postSubmit).isNull(); assertThat(approval.postSubmit).isNull();
assertPermitted( assertPermitted(gApi.changes().id(changeId).get(DETAILED_LABELS), "Code-Review", 1, 2);
gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)), "Code-Review", 1, 2);
// Repeating the current label is allowed. Does not flip the postSubmit bit // Repeating the current label is allowed. Does not flip the postSubmit bit
// due to deduplication codepath. // due to deduplication codepath.
@@ -190,7 +187,7 @@ public class RevisionIT extends AbstractDaemonTest {
approval = getApproval(changeId, label); approval = getApproval(changeId, label);
assertThat(approval.value).isEqualTo(2); assertThat(approval.value).isEqualTo(2);
assertThat(approval.postSubmit).isTrue(); assertThat(approval.postSubmit).isTrue();
assertPermitted(gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)), "Code-Review", 2); assertPermitted(gApi.changes().id(changeId).get(DETAILED_LABELS), "Code-Review", 2);
// Decreasing to previous post-submit vote is still not allowed. // Decreasing to previous post-submit vote is still not allowed.
try { try {
@@ -241,7 +238,7 @@ public class RevisionIT extends AbstractDaemonTest {
ApprovalInfo cr = ApprovalInfo cr =
gApi.changes() gApi.changes()
.id(changeId) .id(changeId)
.get(EnumSet.of(ListChangesOption.DETAILED_LABELS)) .get(DETAILED_LABELS)
.labels .labels
.get("Code-Review") .get("Code-Review")
.all .all
@@ -1359,7 +1356,7 @@ public class RevisionIT extends AbstractDaemonTest {
} }
private ApprovalInfo getApproval(String changeId, String label) throws Exception { private ApprovalInfo getApproval(String changeId, String label) throws Exception {
ChangeInfo info = gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)); ChangeInfo info = gApi.changes().id(changeId).get(DETAILED_LABELS);
LabelInfo li = info.labels.get(label); LabelInfo li = info.labels.get(label);
assertThat(li).isNotNull(); assertThat(li).isNotNull();
int accountId = atrScope.get().getUser().getAccountId().get(); int accountId = atrScope.get().getUser().getAccountId().get();

View File

@@ -22,6 +22,8 @@ import static com.google.gerrit.acceptance.GitUtil.assertPushRejected;
import static com.google.gerrit.acceptance.GitUtil.pushHead; import static com.google.gerrit.acceptance.GitUtil.pushHead;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME; import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import static com.google.gerrit.common.FooterConstants.CHANGE_ID; import static com.google.gerrit.common.FooterConstants.CHANGE_ID;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.common.EditInfoSubject.assertThat; import static com.google.gerrit.extensions.common.EditInfoSubject.assertThat;
import static com.google.gerrit.server.git.receive.ReceiveConstants.PUSH_OPTION_SKIP_VALIDATION; import static com.google.gerrit.server.git.receive.ReceiveConstants.PUSH_OPTION_SKIP_VALIDATION;
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
@@ -1640,8 +1642,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
String ref = "refs/for/master%merged"; String ref = "refs/for/master%merged";
assertPushOk(pushHead(testRepo, ref, false), ref); assertPushOk(pushHead(testRepo, ref, false), ref);
EnumSet<ListChangesOption> opts = EnumSet.of(ListChangesOption.ALL_REVISIONS); ChangeInfo info = gApi.changes().id(r.getChangeId()).get(ALL_REVISIONS);
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(opts);
assertThat(info.currentRevision).isEqualTo(c2.name()); assertThat(info.currentRevision).isEqualTo(c2.name());
assertThat(info.revisions.keySet()).containsExactly(c1.name(), c2.name()); assertThat(info.revisions.keySet()).containsExactly(c1.name(), c2.name());
// TODO(dborowitz): Fix ReceiveCommits to also auto-close the change. // TODO(dborowitz): Fix ReceiveCommits to also auto-close the change.
@@ -1849,12 +1850,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
private String getLastMessage(String changeId) throws Exception { private String getLastMessage(String changeId) throws Exception {
return Streams.findLast( return Streams.findLast(
gApi.changes() gApi.changes().id(changeId).get(MESSAGES).messages.stream().map(m -> m.message))
.id(changeId)
.get(EnumSet.of(ListChangesOption.MESSAGES))
.messages
.stream()
.map(m -> m.message))
.get(); .get();
} }

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume; import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -39,7 +40,6 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
import com.google.gerrit.extensions.api.changes.RevisionApi; import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.changes.SubmitInput; import com.google.gerrit.extensions.api.changes.SubmitInput;
import com.google.gerrit.extensions.api.groups.GroupInput; import com.google.gerrit.extensions.api.groups.GroupInput;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.Side; import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.AccountInfo; import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
@@ -64,7 +64,6 @@ import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.Util; import com.google.gerrit.server.project.Util;
import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeData;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.EnumSet;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.junit.After; import org.junit.After;
@@ -545,8 +544,7 @@ public class ImpersonationIT extends AbstractDaemonTest {
setApiUser(accountCreator.user2()); setApiUser(accountCreator.user2());
gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in); gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in);
ChangeInfo info = ChangeInfo info = gApi.changes().id(r.getChangeId()).get(MESSAGES);
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.MESSAGES));
assertThat(info.messages).hasSize(2); assertThat(info.messages).hasSize(2);
ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages); ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages);

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.acceptance.rest.change; package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS; import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION; import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
@@ -316,7 +317,7 @@ public class ActionsIT extends AbstractDaemonTest {
@Test @Test
public void changeActionVisitor() throws Exception { public void changeActionVisitor() throws Exception {
String id = createChange().getChangeId(); String id = createChange().getChangeId();
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)); ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
class Visitor implements ActionVisitor { class Visitor implements ActionVisitor {
@Override @Override
@@ -362,7 +363,7 @@ public class ActionsIT extends AbstractDaemonTest {
public void currentRevisionActionVisitor() throws Exception { public void currentRevisionActionVisitor() throws Exception {
String id = createChange().getChangeId(); String id = createChange().getChangeId();
amendChange(id); amendChange(id);
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)); ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
Change.Id changeId = new Change.Id(origChange._number); Change.Id changeId = new Change.Id(origChange._number);
class Visitor implements ActionVisitor { class Visitor implements ActionVisitor {
@@ -429,7 +430,7 @@ public class ActionsIT extends AbstractDaemonTest {
public void oldRevisionActionVisitor() throws Exception { public void oldRevisionActionVisitor() throws Exception {
String id = createChange().getChangeId(); String id = createChange().getChangeId();
amendChange(id); amendChange(id);
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)); ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
class Visitor implements ActionVisitor { class Visitor implements ActionVisitor {
@Override @Override

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume; import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@@ -28,13 +29,11 @@ import com.google.gerrit.extensions.api.changes.AddReviewerResult;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.projects.ConfigInput; import com.google.gerrit.extensions.api.projects.ConfigInput;
import com.google.gerrit.extensions.client.InheritableBoolean; import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState; import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.common.AccountInfo; import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.server.mail.Address; import com.google.gerrit.server.mail.Address;
import com.google.gerrit.testutil.FakeEmailSender.Message; import com.google.gerrit.testutil.FakeEmailSender.Message;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -62,8 +61,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
input.state = state; input.state = state;
gApi.changes().id(r.getChangeId()).addReviewer(input); gApi.changes().id(r.getChangeId()).addReviewer(input);
ChangeInfo info = ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc))); assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
// All reviewers added by email should be removable // All reviewers added by email should be removable
assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(acc)); assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(acc));
@@ -89,8 +87,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
inputById.state = state; inputById.state = state;
gApi.changes().id(r.getChangeId()).addReviewer(inputById); gApi.changes().id(r.getChangeId()).addReviewer(inputById);
ChangeInfo info = ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(byId, byEmail))); assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(byId, byEmail)));
// All reviewers (both by id and by email) should be removable // All reviewers (both by id and by email) should be removable
assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(byId, byEmail)); assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(byId, byEmail));
@@ -112,8 +109,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
gApi.changes().id(r.getChangeId()).reviewer(acc.email).remove(); gApi.changes().id(r.getChangeId()).reviewer(acc.email).remove();
ChangeInfo info = ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
assertThat(info.reviewers).isEmpty(); assertThat(info.reviewers).isEmpty();
} }
} }
@@ -135,8 +131,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
modifyInput.state = ReviewerState.REVIEWER; modifyInput.state = ReviewerState.REVIEWER;
gApi.changes().id(r.getChangeId()).addReviewer(modifyInput); gApi.changes().id(r.getChangeId()).addReviewer(modifyInput);
ChangeInfo info = ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
assertThat(info.reviewers) assertThat(info.reviewers)
.isEqualTo(ImmutableMap.of(ReviewerState.REVIEWER, ImmutableList.of(acc))); .isEqualTo(ImmutableMap.of(ReviewerState.REVIEWER, ImmutableList.of(acc)));
} }
@@ -329,10 +324,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
try { try {
ChangeInfo info = ChangeInfo info =
Iterables.getOnlyElement( Iterables.getOnlyElement(
gApi.changes() gApi.changes().query(r.getChangeId()).withOption(DETAILED_LABELS).get());
.query(r.getChangeId())
.withOption(ListChangesOption.DETAILED_LABELS)
.get());
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc))); assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
} finally { } finally {
notesMigration.setFailOnLoadForTest(false); notesMigration.setFailOnLoadForTest(false);

View File

@@ -48,7 +48,6 @@ import com.google.gerrit.testutil.FakeEmailSender.Message;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -806,6 +805,6 @@ public class ChangeReviewersIT extends AbstractDaemonTest {
} }
private Map<String, LabelInfo> getChangeLabels(String changeId) throws Exception { private Map<String, LabelInfo> getChangeLabels(String changeId) throws Exception {
return gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)).labels; return gApi.changes().id(changeId).get(DETAILED_LABELS).labels;
} }
} }

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_; import static com.google.common.truth.Truth.assert_;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static com.google.common.truth.TruthJUnit.assume; import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@@ -26,7 +27,6 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.common.TimeUtil; import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.BatchUpdate;
@@ -39,7 +39,6 @@ import com.google.gerrit.testutil.ConfigSuite;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@@ -280,7 +279,7 @@ public class NoteDbOnlyIT extends AbstractDaemonTest {
private List<String> getMessages(Change.Id id) throws Exception { private List<String> getMessages(Change.Id id) throws Exception {
return gApi.changes() return gApi.changes()
.id(id.get()) .id(id.get())
.get(EnumSet.of(ListChangesOption.MESSAGES)) .get(MESSAGES)
.messages .messages
.stream() .stream()
.map(m -> m.message) .map(m -> m.message)

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.extensions.api.changes; package com.google.gerrit.extensions.api.changes;
import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.client.ListChangesOption; import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo; import com.google.gerrit.extensions.common.AccountInfo;
@@ -27,6 +28,7 @@ import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.common.SuggestedReviewerInfo; import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -170,6 +172,14 @@ public interface ChangeApi {
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException; ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
default ChangeInfo get(Iterable<ListChangesOption> options) throws RestApiException {
return get(Sets.newEnumSet(options, ListChangesOption.class));
}
default ChangeInfo get(ListChangesOption... options) throws RestApiException {
return get(Arrays.asList(options));
}
/** {@code get} with {@link ListChangesOption} set to all except CHECK. */ /** {@code get} with {@link ListChangesOption} set to all except CHECK. */
ChangeInfo get() throws RestApiException; ChangeInfo get() throws RestApiException;
/** {@code get} with {@link ListChangesOption} set to none. */ /** {@code get} with {@link ListChangesOption} set to none. */