Label-predicate: Add support for change owner votes
Change owner votes may have special meanings and different workflows
may be enforced for them:
o reject votes by change owner can denote Work In Progress (WIP) changes
o approval votes by change owner can mean multiple things, depending on
project policies:
oo review schould not be done on those changes and the change is
only uploaded for verification purposes on different platform and
architecture combinations
oo auto_merge self approved changes when verification was successful
oo enforcing "non-self approval policy", but not forbidding it to
still be able to self approve changes in emergency cases.
Given that this is exception from the policy, there should be an
easy way to detect this policy violation with native gerrit
predicate
Currently there is no built in way to detect change owner votes.
Having a built in way and not depending on external scripts to detect
change owner votes, would create addition value by allowing to combine
different predicates and use the result in gerrit itself, e.g.
dashboards can skip WIP changes.
This change extends label predicate semantic by adding additional
value for change owner votes: "label,owner". Schema version is bumped
to force reindexing. Label field is renamed to Label2 and query parser
is taught to route to the correct predicate depending on the live index
version.
With this change, change owner votes can be detected and used in
different workflows:
o skip WIP changes, rejected by change owner:
is:open NOT label:Code-Review-2,owner
o skip non reviewable changes, approval by change owner:
is:open NOT label:Code-Review+2,owner
o suggest changes for auto merge: approval by change owner + verify
by the bot (assuming default label set: CRVW + VRFY):
project:foo
branch:master
is:open
is:mergeable
label:Code-Review+2,owner
label:Verified+1,buildbot
NOT label:Code-Review-2
NOT label:Verified-1
o detect changes, that violates "non-self approval policy":
label:Code-Review+2,owner
Change-Id: I56ff6b1416f099dc627794c175aa4c2de3f2db9f
This commit is contained in:
@@ -429,26 +429,47 @@ public class ChangeField {
|
||||
};
|
||||
|
||||
/** List of labels on the current patch set. */
|
||||
@Deprecated
|
||||
public static final FieldDef<ChangeData, Iterable<String>> LABEL =
|
||||
new FieldDef.Repeatable<ChangeData, String>(
|
||||
ChangeQueryBuilder.FIELD_LABEL, FieldType.EXACT, false) {
|
||||
@Override
|
||||
public Iterable<String> get(ChangeData input, FillArgs args)
|
||||
throws OrmException {
|
||||
Set<String> allApprovals = new HashSet<>();
|
||||
Set<String> distinctApprovals = new HashSet<>();
|
||||
for (PatchSetApproval a : input.currentApprovals()) {
|
||||
if (a.getValue() != 0 && !a.isLegacySubmit()) {
|
||||
allApprovals.add(formatLabel(a.getLabel(), a.getValue(),
|
||||
a.getAccountId()));
|
||||
distinctApprovals.add(formatLabel(a.getLabel(), a.getValue()));
|
||||
}
|
||||
}
|
||||
allApprovals.addAll(distinctApprovals);
|
||||
return allApprovals;
|
||||
return getLabels(input, false);
|
||||
}
|
||||
};
|
||||
|
||||
/** List of labels on the current patch set including change owner votes. */
|
||||
public static final FieldDef<ChangeData, Iterable<String>> LABEL2 =
|
||||
new FieldDef.Repeatable<ChangeData, String>(
|
||||
"label2", FieldType.EXACT, false) {
|
||||
@Override
|
||||
public Iterable<String> get(ChangeData input, FillArgs args)
|
||||
throws OrmException {
|
||||
return getLabels(input, true);
|
||||
}
|
||||
};
|
||||
|
||||
private static Iterable<String> getLabels(ChangeData input, boolean owners)
|
||||
throws OrmException {
|
||||
Set<String> allApprovals = new HashSet<>();
|
||||
Set<String> distinctApprovals = new HashSet<>();
|
||||
for (PatchSetApproval a : input.currentApprovals()) {
|
||||
if (a.getValue() != 0 && !a.isLegacySubmit()) {
|
||||
allApprovals.add(formatLabel(a.getLabel(), a.getValue(),
|
||||
a.getAccountId()));
|
||||
if (owners && input.change().getOwner().equals(a.getAccountId())) {
|
||||
allApprovals.add(formatLabel(a.getLabel(), a.getValue(),
|
||||
ChangeQueryBuilder.OWNER_ACCOUNT_ID));
|
||||
}
|
||||
distinctApprovals.add(formatLabel(a.getLabel(), a.getValue()));
|
||||
}
|
||||
}
|
||||
allApprovals.addAll(distinctApprovals);
|
||||
return allApprovals;
|
||||
}
|
||||
|
||||
public static Set<String> getAuthorParts(ChangeData cd) throws OrmException {
|
||||
try {
|
||||
return SchemaUtil.getPersonParts(cd.getAuthor());
|
||||
@@ -544,7 +565,14 @@ public class ChangeField {
|
||||
|
||||
public static String formatLabel(String label, int value, Account.Id accountId) {
|
||||
return label.toLowerCase() + (value >= 0 ? "+" : "") + value
|
||||
+ (accountId != null ? "," + accountId.get() : "");
|
||||
+ (accountId != null ? "," + formatAccount(accountId) : "");
|
||||
}
|
||||
|
||||
private static String formatAccount(Account.Id accountId) {
|
||||
if (ChangeQueryBuilder.OWNER_ACCOUNT_ID.equals(accountId)) {
|
||||
return ChangeQueryBuilder.ARG_ID_OWNER;
|
||||
}
|
||||
return Integer.toString(accountId.get());
|
||||
}
|
||||
|
||||
/** Commit message of the current patch set. */
|
||||
|
||||
@@ -88,9 +88,17 @@ public class ChangeSchemaDefinitions extends SchemaDefinitions<ChangeData> {
|
||||
.add(ChangeField.REVIEWER)
|
||||
.build();
|
||||
|
||||
@Deprecated
|
||||
static final Schema<ChangeData> V33 =
|
||||
schema(V32, ChangeField.ASSIGNEE);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static final Schema<ChangeData> V34 = new Schema.Builder<ChangeData>()
|
||||
.add(V33)
|
||||
.remove(ChangeField.LABEL)
|
||||
.add(ChangeField.LABEL2)
|
||||
.build();
|
||||
|
||||
public static final String NAME = "changes";
|
||||
public static final ChangeSchemaDefinitions INSTANCE =
|
||||
new ChangeSchemaDefinitions();
|
||||
|
||||
Reference in New Issue
Block a user