diff --git a/Documentation/cmd-query.txt b/Documentation/cmd-query.txt index 2ad3b7a49d..2feea114c8 100644 --- a/Documentation/cmd-query.txt +++ b/Documentation/cmd-query.txt @@ -16,6 +16,7 @@ SYNOPSIS [--comments] [--commit-message] [--dependencies] + [--submit-records] [--] [limit:] @@ -80,6 +81,11 @@ OPTIONS Show information about patch sets which depend on, or are needed by, each patch set. +--submit-records:: + Show submit record information about the change, which + includes whether the change meets the criteria for submission + (including information for each review label). + limit::: Maximum number of results to return. This is actually a query operator, and not a command line option. If more diff --git a/Documentation/json.txt b/Documentation/json.txt index 58e8e8fd79..f0588ceb17 100644 --- a/Documentation/json.txt +++ b/Documentation/json.txt @@ -57,6 +57,9 @@ currentPatchSet:: Current <>. patchSets:: All <> for this change. +submitRecords:: The <> contains +information about whether this change has been or can be submitted. + [[trackingid]] trackingid ---------- @@ -134,6 +137,47 @@ min:: lower limit max:: upper limit +[[submitRecord]] +submitRecord +------------ +Information about the submit status of a change. + +status:: Current submit status. + + OK;; The change is ready for submission or already submitted. + + NOT_READY;; The change is missing a required label. + + RULE_ERROR;; An internal server error occurred preventing computation. + +labels:: This describes the state of each code review +<>, unless the status is RULE_ERROR. + +[[label]] +label +----- +Information about a code review label for a change. + +label:: The name of the label. + +status:: The status of the label. + + OK;; This label provides what is necessary for submission. + + REJECT;; This label prevents the change from being submitted. + + NEED;; The label is required for submission, but has not + been satisfied. + + MAY;; The label may be set, but it's neither necessary for + submission nor does it block submission if set. + + IMPOSSIBLE;; The label is required for submission, but is impossible + to complete. The likely cause is access has not been granted + correctly by the project owner or site administrator. + +by:: The <> that applied the label. + SEE ALSO -------- diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/ChangeAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/ChangeAttribute.java index 9810f59d28..5150b48e2f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/events/ChangeAttribute.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/ChangeAttribute.java @@ -42,4 +42,5 @@ public class ChangeAttribute { public List dependsOn; public List neededBy; + public List submitRecords; } 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 41cac4e2ed..ab3ca56fc5 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 @@ -16,6 +16,7 @@ package com.google.gerrit.server.events; import com.google.gerrit.common.data.ApprovalType; import com.google.gerrit.common.data.ApprovalTypes; +import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Change; @@ -46,6 +47,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import java.util.List; import javax.annotation.Nullable; @@ -121,6 +123,47 @@ public class EventFactory { a.status = change.getStatus(); } + /** + * Add submitRecords to an existing ChangeAttribute. + * + * @param ca + * @param submitRecords + */ + public void addSubmitRecords(ChangeAttribute ca, + List submitRecords) { + ca.submitRecords = new ArrayList(); + + for (SubmitRecord submitRecord : submitRecords) { + SubmitRecordAttribute sa = new SubmitRecordAttribute(); + sa.status = submitRecord.status.name(); + if (submitRecord.status != SubmitRecord.Status.RULE_ERROR) { + addSubmitRecordLabels(submitRecord, sa); + } + ca.submitRecords.add(sa); + } + // Remove empty lists so a confusing label won't be displayed in the output. + if (ca.submitRecords.isEmpty()) { + ca.submitRecords = null; + } + } + + private void addSubmitRecordLabels(SubmitRecord submitRecord, + SubmitRecordAttribute sa) { + if (submitRecord.labels != null && !submitRecord.labels.isEmpty()) { + sa.labels = new ArrayList(); + for (SubmitRecord.Label lbl : submitRecord.labels) { + SubmitLabelAttribute la = new SubmitLabelAttribute(); + la.label = lbl.label; + la.status = lbl.status.name(); + if(lbl.appliedBy != null) { + Account a = accountCache.get(lbl.appliedBy).getAccount(); + la.by = asAccountAttribute(a); + } + sa.labels.add(la); + } + } + } + public void addDependencies(ChangeAttribute ca, Change change) { ca.dependsOn = new ArrayList(); ca.neededBy = new ArrayList(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitLabelAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitLabelAttribute.java new file mode 100644 index 0000000000..99d0350842 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitLabelAttribute.java @@ -0,0 +1,21 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.events; + +public class SubmitLabelAttribute { + public String label; + public String status; + public AccountAttribute by; +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitRecordAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitRecordAttribute.java new file mode 100644 index 0000000000..04b76e1287 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/SubmitRecordAttribute.java @@ -0,0 +1,22 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.events; + +import java.util.List; + +public class SubmitRecordAttribute { + public String status; + public List labels; +} 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 76945f4fc8..f44282a2f9 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 @@ -15,6 +15,7 @@ package com.google.gerrit.server.query.change; import com.google.gerrit.common.data.GlobalCapability; +import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -105,6 +106,7 @@ public class QueryProcessor { private boolean includeFiles; private boolean includeCommitMessage; private boolean includeDependencies; + private boolean includeSubmitRecords; private OutputStream outputStream = DisabledOutputStream.INSTANCE; private PrintWriter out; @@ -184,6 +186,10 @@ public class QueryProcessor { includeCommitMessage = on; } + public void setIncludeSubmitRecords(boolean on) { + includeSubmitRecords = on; + } + public void setOutput(OutputStream out, OutputFormat fmt) { this.outputStream = out; this.outputFormat = fmt; @@ -259,6 +265,15 @@ public class QueryProcessor { eventFactory.extend(c, d.getChange()); eventFactory.addTrackingIds(c, d.trackingIds(db)); + if (includeSubmitRecords) { + PatchSet.Id psId = d.getChange().currentPatchSetId(); + PatchSet patchSet = db.get().patchSets().get(psId); + Change.Id changeId = psId.getParentKey(); + List submitResult = d.changeControl().canSubmit( // + db.get(), patchSet, null, false, true); + eventFactory.addSubmitRecords(c, submitResult); + } + if (includeCommitMessage) { eventFactory.addCommitMessage(c, d.commitMessage(repoManager, db)); } 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 2db13a4a4e..63680f868e 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 @@ -70,6 +70,11 @@ class Query extends SshCommand { processor.setIncludeDependencies(on); } + @Option(name = "--submit-records", usage = "Include submit and label status") + void setSubmitRecords(boolean on) { + processor.setIncludeSubmitRecords(on); + } + @Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute") private List query;