Add submit records to query output.
Add a command line option to the gerrit query ssh command to include
submit records in output.
This facilitates the querying of information relating to the submit status
from the command line and by API clients, including information such as
whether the change can be submitted as-is, and whether the submission
criteria for each review label has been met. Example output:
submitRecords:
status: NOT_READY
labels:
label: Verified
status: OK
by:
name: James E. Blair
email: corvus@example.com
username: corvus
labels:
label: Code-Review
status: NEED
Change-Id: If13393aadfcce75a049d9b15c7467cb8df5570d9
This commit is contained in:
@@ -16,6 +16,7 @@ SYNOPSIS
|
||||
[--comments]
|
||||
[--commit-message]
|
||||
[--dependencies]
|
||||
[--submit-records]
|
||||
[--]
|
||||
<query>
|
||||
[limit:<n>]
|
||||
@@ -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:<n>::
|
||||
Maximum number of results to return. This is actually a
|
||||
query operator, and not a command line option. If more
|
||||
|
||||
@@ -57,6 +57,9 @@ currentPatchSet:: Current <<patchSet,patchSet attribute>>.
|
||||
|
||||
patchSets:: All <<patchSet,patchSet attribute>> for this change.
|
||||
|
||||
submitRecords:: The <<submitRecord,submitRecord attribute>> 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
|
||||
<<label,label attribute>>, 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 <<account,account>> that applied the label.
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
||||
|
||||
@@ -42,4 +42,5 @@ public class ChangeAttribute {
|
||||
|
||||
public List<DependencyAttribute> dependsOn;
|
||||
public List<DependencyAttribute> neededBy;
|
||||
public List<SubmitRecordAttribute> submitRecords;
|
||||
}
|
||||
|
||||
@@ -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<SubmitRecord> submitRecords) {
|
||||
ca.submitRecords = new ArrayList<SubmitRecordAttribute>();
|
||||
|
||||
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<SubmitLabelAttribute>();
|
||||
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<DependencyAttribute>();
|
||||
ca.neededBy = new ArrayList<DependencyAttribute>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<SubmitLabelAttribute> labels;
|
||||
}
|
||||
@@ -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<SubmitRecord> submitResult = d.changeControl().canSubmit( //
|
||||
db.get(), patchSet, null, false, true);
|
||||
eventFactory.addSubmitRecords(c, submitResult);
|
||||
}
|
||||
|
||||
if (includeCommitMessage) {
|
||||
eventFactory.addCommitMessage(c, d.commitMessage(repoManager, db));
|
||||
}
|
||||
|
||||
@@ -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<String> query;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user