Add --all-reviewers to ssh gerrit-query
The new allReviewers parameter allows users to view the name and
email of all reviewers which are added to a change (irrespective of
whether they have been voting on that change or not).
Feature: Issue 2102
Change-Id: I655a49c37b959eb2f0bb705e2c45cb9bdc33ea23
diff --git a/Documentation/cmd-query.txt b/Documentation/cmd-query.txt
index 66bd845..f7a784f 100644
--- a/Documentation/cmd-query.txt
+++ b/Documentation/cmd-query.txt
@@ -17,6 +17,7 @@
[--commit-message]
[--dependencies]
[--submit-records]
+ [--all-reviewers]
[--]
<query>
[limit:<n>]
@@ -89,6 +90,10 @@
Show information about patch sets which depend on, or are needed by,
each patch set.
+--all-reviewers::
+ Show the name and email of all reviewers which are added to a change
+ (irrespective of whether they have been voting on that change or not).
+
--submit-records::
Show submit record information about the change, which
includes whether the change meets the criteria for submission
diff --git a/Documentation/json.txt b/Documentation/json.txt
index 2836e5b..9278cde 100644
--- a/Documentation/json.txt
+++ b/Documentation/json.txt
@@ -72,6 +72,9 @@
submitRecords:: The <<submitRecord,submitRecord attribute>> contains
information about whether this change has been or can be submitted.
+allReviewers:: List of all reviewers in <<account,account attribute>>
+which are added to a change.
+
[[trackingid]]
trackingid
----------
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/data/ChangeAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/data/ChangeAttribute.java
index 7339829..5f5fd33 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/data/ChangeAttribute.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/data/ChangeAttribute.java
@@ -43,4 +43,5 @@
public List<DependencyAttribute> dependsOn;
public List<DependencyAttribute> neededBy;
public List<SubmitRecordAttribute> submitRecords;
+ public List<AccountAttribute> allReviewers;
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java
index 98e803f..58d16dc 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java
@@ -14,6 +14,8 @@
package com.google.gerrit.server.events;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelTypes;
@@ -69,6 +71,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Set;
@Singleton
public class EventFactory {
@@ -158,6 +161,29 @@
}
/**
+ * Add allReviewers to an existing ChangeAttribute.
+ *
+ * @param a
+ * @param change
+ */
+ public void addAllReviewers(ChangeAttribute a, Change change)
+ throws OrmException {
+ List<PatchSetApproval> approvals =
+ db.get().patchSetApprovals().byChange(change.getId()).toList();
+ if (!approvals.isEmpty()) {
+ a.allReviewers = Lists.newArrayList();
+ Set<Account.Id> seen = Sets.newHashSet();
+ for (PatchSetApproval psa : approvals) {
+ Account.Id id = psa.getAccountId();
+ if (!seen.contains(id)) {
+ seen.add(id);
+ a.allReviewers.add(asAccountAttribute(id));
+ }
+ }
+ }
+ }
+
+ /**
* Add submitRecords to an existing ChangeAttribute.
*
* @param ca
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java
index 5624f45..e569ff5 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java
@@ -113,6 +113,7 @@
private boolean includeCommitMessage;
private boolean includeDependencies;
private boolean includeSubmitRecords;
+ private boolean includeAllReviewers;
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
private PrintWriter out;
@@ -200,6 +201,10 @@
includeSubmitRecords = on;
}
+ public void setIncludeAllReviewers(boolean on) {
+ includeAllReviewers = on;
+ }
+
public void setOutput(OutputStream out, OutputFormat fmt) {
this.outputStream = out;
this.outputFormat = fmt;
@@ -304,6 +309,10 @@
eventFactory.extend(c, d.getChange());
eventFactory.addTrackingIds(c, d.trackingIds(db));
+ if (includeAllReviewers) {
+ eventFactory.addAllReviewers(c, d.getChange());
+ }
+
if (includeSubmitRecords) {
PatchSet.Id psId = d.getChange().currentPatchSetId();
PatchSet patchSet = db.get().patchSets().get(psId);
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java
index 185bb67..af42e1b 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java
@@ -72,6 +72,11 @@
processor.setIncludeDependencies(on);
}
+ @Option(name = "--all-reviewers", usage = "Include all reviewers")
+ void setAllReviewers(boolean on) {
+ processor.setIncludeAllReviewers(on);
+ }
+
@Option(name = "--submit-records", usage = "Include submit and label status")
void setSubmitRecords(boolean on) {
processor.setIncludeSubmitRecords(on);