Add a --all-approvals option to queries
The new --all-approvals option in queries enables the approvals to be displayed inline with each patchset. This option therefore implies the --patch-sets option. Bug: issue 729 Change-Id: Iace6ce9673f3d54c102af5550ebed0c4c5cb5053
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.inject.internal.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class EventFactory {
|
||||
@@ -89,10 +90,19 @@ public class EventFactory {
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) {
|
||||
addPatchSets(a, ps, null);
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals) {
|
||||
if (!ps.isEmpty()) {
|
||||
a.patchSets = new ArrayList<PatchSetAttribute>(ps.size());
|
||||
ca.patchSets = new ArrayList<PatchSetAttribute>(ps.size());
|
||||
for (PatchSet p : ps) {
|
||||
a.patchSets.add(asPatchSetAttribute(p));
|
||||
PatchSetAttribute psa = asPatchSetAttribute(p);
|
||||
if (approvals != null) {
|
||||
addApprovals(psa, p.getId(), approvals);
|
||||
}
|
||||
ca.patchSets.add(psa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +130,14 @@ public class EventFactory {
|
||||
return p;
|
||||
}
|
||||
|
||||
public void addApprovals(PatchSetAttribute p, PatchSet.Id id,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> all) {
|
||||
Collection<PatchSetApproval> list = all.get(id);
|
||||
if (list != null) {
|
||||
addApprovals(p, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void addApprovals(PatchSetAttribute p,
|
||||
Collection<PatchSetApproval> list) {
|
||||
if (!list.isEmpty()) {
|
||||
|
||||
@@ -32,13 +32,16 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChangeData {
|
||||
private final Change.Id legacyId;
|
||||
private Change change;
|
||||
private Collection<PatchSet> patches;
|
||||
private Collection<PatchSetApproval> approvals;
|
||||
private Map<PatchSet.Id,Collection<PatchSetApproval>> approvalsMap;
|
||||
private Collection<PatchSetApproval> currentApprovals;
|
||||
private String[] currentFiles;
|
||||
private Collection<PatchLineComment> comments;
|
||||
@@ -175,6 +178,23 @@ public class ChangeData {
|
||||
return approvals;
|
||||
}
|
||||
|
||||
public Map<PatchSet.Id,Collection<PatchSetApproval>> approvalsMap(Provider<ReviewDb> db)
|
||||
throws OrmException {
|
||||
if (approvalsMap == null) {
|
||||
Collection<PatchSetApproval> all = approvals(db);
|
||||
approvalsMap = new HashMap<PatchSet.Id,Collection<PatchSetApproval>>(all.size());
|
||||
for (PatchSetApproval psa : all) {
|
||||
Collection<PatchSetApproval> c = approvalsMap.get(psa.getPatchSetId());
|
||||
if (c == null) {
|
||||
c = new ArrayList<PatchSetApproval>();
|
||||
approvalsMap.put(psa.getPatchSetId(), c);
|
||||
}
|
||||
c.add(psa);
|
||||
}
|
||||
}
|
||||
return approvalsMap;
|
||||
}
|
||||
|
||||
public Collection<PatchLineComment> comments(Provider<ReviewDb> db)
|
||||
throws OrmException {
|
||||
if (comments == null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.events.ChangeAttribute;
|
||||
import com.google.gerrit.server.events.EventFactory;
|
||||
import com.google.gerrit.server.events.PatchSetAttribute;
|
||||
import com.google.gerrit.server.events.QueryStats;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
@@ -69,6 +70,7 @@ public class QueryProcessor {
|
||||
private OutputFormat outputFormat = OutputFormat.TEXT;
|
||||
private boolean includePatchSets;
|
||||
private boolean includeCurrentPatchSet;
|
||||
private boolean includeApprovals;
|
||||
|
||||
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
|
||||
private PrintWriter out;
|
||||
@@ -91,6 +93,10 @@ public class QueryProcessor {
|
||||
includeCurrentPatchSet = on;
|
||||
}
|
||||
|
||||
public void setIncludeApprovals(boolean on) {
|
||||
includeApprovals = on;
|
||||
}
|
||||
|
||||
public void setOutput(OutputStream out, OutputFormat fmt) {
|
||||
this.outputStream = out;
|
||||
this.outputFormat = fmt;
|
||||
@@ -151,7 +157,8 @@ public class QueryProcessor {
|
||||
eventFactory.addTrackingIds(c, d.trackingIds(db));
|
||||
|
||||
if (includePatchSets) {
|
||||
eventFactory.addPatchSets(c, d.patches(db));
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null);
|
||||
}
|
||||
|
||||
if (includeCurrentPatchSet) {
|
||||
|
||||
Reference in New Issue
Block a user