Merge "Support branch specific labels"
This commit is contained in:
@@ -59,6 +59,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -127,6 +128,7 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
private static final String KEY_COPY_MAX_SCORE = "copyMaxScore";
|
||||
private static final String KEY_VALUE = "value";
|
||||
private static final String KEY_CAN_OVERRIDE = "canOverride";
|
||||
private static final String KEY_Branch = "branch";
|
||||
private static final Set<String> LABEL_FUNCTIONS = ImmutableSet.of(
|
||||
"MaxWithBlock", "AnyWithBlock", "MaxNoBlock", "NoBlock", "NoOp");
|
||||
|
||||
@@ -651,10 +653,17 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
rc.getBoolean(LABEL, name, KEY_COPY_MAX_SCORE, false));
|
||||
label.setCanOverride(
|
||||
rc.getBoolean(LABEL, name, KEY_CAN_OVERRIDE, true));
|
||||
label.setRefPatterns(getStringListOrNull(rc, LABEL, name, KEY_Branch));
|
||||
labelSections.put(name, label);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getStringListOrNull(Config rc, String section,
|
||||
String subSection, String name) {
|
||||
String[] ac = rc.getStringList(section, subSection, name);
|
||||
return ac.length == 0 ? null : Arrays.asList(ac);
|
||||
}
|
||||
|
||||
private void loadCommentLinkSections(Config rc) {
|
||||
Set<String> subsections = rc.getSubsections(COMMENTLINK);
|
||||
commentLinkSections = Lists.newArrayListWithCapacity(subsections.size());
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.RefConfigSection;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.common.data.SubmitTypeRecord;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -242,9 +245,28 @@ public class ChangeControl {
|
||||
&& getRefControl().canUpload(); // as long as you can upload too
|
||||
}
|
||||
|
||||
/** All available label types for this project. */
|
||||
/** All available label types for this change. */
|
||||
public LabelTypes getLabelTypes() {
|
||||
return getProjectControl().getLabelTypes();
|
||||
String destBranch = getChange().getDest().get();
|
||||
List<LabelType> all = getProjectControl().getLabelTypes().getLabelTypes();
|
||||
|
||||
List<LabelType> r = Lists.newArrayListWithCapacity(all.size());
|
||||
for (LabelType l : all) {
|
||||
List<String> refs = l.getRefPatterns();
|
||||
if (refs == null) {
|
||||
r.add(l);
|
||||
} else {
|
||||
for (String refPattern : refs) {
|
||||
if (RefConfigSection.isValid(refPattern)
|
||||
&& match(destBranch, refPattern)) {
|
||||
r.add(l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new LabelTypes(r);
|
||||
}
|
||||
|
||||
/** All value ranges of any allowed label permission. */
|
||||
@@ -403,6 +425,11 @@ public class ChangeControl {
|
||||
return resultsToSubmitRecord(evaluator.getSubmitRule(), results);
|
||||
}
|
||||
|
||||
private boolean match(String destBranch, String refPattern) {
|
||||
return RefPatternMatcher.getMatcher(refPattern).match(destBranch,
|
||||
this.getRefControl().getCurrentUser().getUserName());
|
||||
}
|
||||
|
||||
private List<SubmitRecord> cannotSubmitDraft(ReviewDb db, PatchSet patchSet,
|
||||
ChangeData cd) {
|
||||
try {
|
||||
|
||||
@@ -16,9 +16,7 @@ package gerrit;
|
||||
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.rules.PrologEnvironment;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.IntegerTerm;
|
||||
import com.googlecode.prolog_cafe.lang.ListTerm;
|
||||
@@ -55,14 +53,8 @@ class PRED_get_legacy_label_types_1 extends Predicate.P1 {
|
||||
public Operation exec(Prolog engine) throws PrologException {
|
||||
engine.setB0();
|
||||
Term a1 = arg1.dereference();
|
||||
|
||||
PrologEnvironment env = (PrologEnvironment) engine.control;
|
||||
ProjectState state = env.getArgs().getProjectCache()
|
||||
.get(StoredValues.CHANGE.get(engine).getDest().getParentKey());
|
||||
if (state == null) {
|
||||
return engine.fail();
|
||||
}
|
||||
List<LabelType> list = state.getLabelTypes().getLabelTypes();
|
||||
List<LabelType> list =
|
||||
StoredValues.CHANGE_CONTROL.get(engine).getLabelTypes().getLabelTypes();
|
||||
Term head = Prolog.Nil;
|
||||
for (int idx = list.size() - 1; 0 <= idx; idx--) {
|
||||
head = new ListTerm(export(list.get(idx)), head);
|
||||
|
||||
Reference in New Issue
Block a user