use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class LabelsJson method setLabelValues.
private void setLabelValues(LabelType type, LabelWithStatus l) {
l.label().defaultValue = type.getDefaultValue();
l.label().values = new LinkedHashMap<>();
for (LabelValue v : type.getValues()) {
l.label().values.put(v.formatValue(), v.getText());
}
if (isOnlyZero(l.label().values.keySet())) {
l.label().values = null;
}
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class PRED_get_legacy_label_types_1 method export.
static Term export(LabelType type) {
LabelValue min = type.getMin();
LabelValue max = type.getMax();
return new StructureTerm(symLabelType, SymbolTerm.intern(type.getName()), SymbolTerm.intern(type.getFunction().getFunctionName()), min != null ? new IntegerTerm(min.getValue()) : NONE, max != null ? new IntegerTerm(max.getValue()) : NONE);
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class LabelNormalizer method applyTypeFloor.
private PatchSetApproval applyTypeFloor(LabelType lt, PatchSetApproval a) {
PatchSetApproval.Builder b = a.toBuilder();
LabelValue atMin = lt.getMin();
if (atMin != null && a.value() < atMin.getValue()) {
b.value(atMin.getValue());
}
LabelValue atMax = lt.getMax();
if (atMax != null && a.value() > atMax.getValue()) {
b.value(atMax.getValue());
}
return b.build();
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class ProjectConfig method loadLabelSections.
private void loadLabelSections(Config rc) {
Map<String, String> lowerNames = Maps.newHashMapWithExpectedSize(2);
labelSections = new LinkedHashMap<>();
for (String name : rc.getSubsections(LABEL)) {
String lower = name.toLowerCase();
if (lowerNames.containsKey(lower)) {
error(String.format("Label \"%s\" conflicts with \"%s\"", name, lowerNames.get(lower)));
}
lowerNames.put(lower, name);
List<LabelValue> values = new ArrayList<>();
Set<Short> allValues = new HashSet<>();
for (String value : rc.getStringList(LABEL, name, KEY_VALUE)) {
try {
LabelValue labelValue = parseLabelValue(value);
if (allValues.add(labelValue.getValue())) {
values.add(labelValue);
} else {
error(String.format("Duplicate %s \"%s\" for label \"%s\"", KEY_VALUE, value, name));
}
} catch (IllegalArgumentException notValue) {
error(String.format("Invalid %s \"%s\" for label \"%s\": %s", KEY_VALUE, value, name, notValue.getMessage()));
}
}
LabelType.Builder label;
try {
label = LabelType.builder(name, values);
} catch (IllegalArgumentException badName) {
error(String.format("Invalid label \"%s\"", name));
continue;
}
label.setDescription(Optional.ofNullable(rc.getString(LABEL, name, KEY_LABEL_DESCRIPTION)));
String functionName = rc.getString(LABEL, name, KEY_FUNCTION);
Optional<LabelFunction> function = functionName != null ? LabelFunction.parse(functionName) : Optional.of(LabelFunction.MAX_WITH_BLOCK);
if (!function.isPresent()) {
error(String.format("Invalid %s for label \"%s\". Valid names are: %s", KEY_FUNCTION, name, Joiner.on(", ").join(LabelFunction.ALL.keySet())));
}
label.setFunction(function.orElse(null));
label.setCopyCondition(rc.getString(LABEL, name, KEY_COPY_CONDITION));
if (!values.isEmpty()) {
short dv = (short) rc.getInt(LABEL, name, KEY_DEFAULT_VALUE, 0);
if (isInRange(dv, values)) {
label.setDefaultValue(dv);
} else {
error(String.format("Invalid %s \"%s\" for label \"%s\"", KEY_DEFAULT_VALUE, dv, name));
}
}
label.setAllowPostSubmit(rc.getBoolean(LABEL, name, KEY_ALLOW_POST_SUBMIT, LabelType.DEF_ALLOW_POST_SUBMIT));
label.setIgnoreSelfApproval(rc.getBoolean(LABEL, name, KEY_IGNORE_SELF_APPROVAL, LabelType.DEF_IGNORE_SELF_APPROVAL));
label.setCopyAnyScore(rc.getBoolean(LABEL, name, KEY_COPY_ANY_SCORE, LabelType.DEF_COPY_ANY_SCORE));
label.setCopyMinScore(rc.getBoolean(LABEL, name, KEY_COPY_MIN_SCORE, LabelType.DEF_COPY_MIN_SCORE));
label.setCopyMaxScore(rc.getBoolean(LABEL, name, KEY_COPY_MAX_SCORE, LabelType.DEF_COPY_MAX_SCORE));
label.setCopyAllScoresIfListOfFilesDidNotChange(rc.getBoolean(LABEL, name, KEY_COPY_ALL_SCORES_IF_LIST_OF_FILES_DID_NOT_CHANGE, LabelType.DEF_COPY_ALL_SCORES_IF_LIST_OF_FILES_DID_NOT_CHANGE));
label.setCopyAllScoresOnMergeFirstParentUpdate(rc.getBoolean(LABEL, name, KEY_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE, LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE));
label.setCopyAllScoresOnTrivialRebase(rc.getBoolean(LABEL, name, KEY_COPY_ALL_SCORES_ON_TRIVIAL_REBASE, LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE));
label.setCopyAllScoresIfNoCodeChange(rc.getBoolean(LABEL, name, KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE, LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE));
label.setCopyAllScoresIfNoChange(rc.getBoolean(LABEL, name, KEY_COPY_ALL_SCORES_IF_NO_CHANGE, LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE));
Set<Short> copyValues = new HashSet<>();
for (String value : rc.getStringList(LABEL, name, KEY_COPY_VALUE)) {
try {
short copyValue = Shorts.checkedCast(PermissionRule.parseInt(value));
if (!copyValues.add(copyValue)) {
error(String.format("Duplicate %s \"%s\" for label \"%s\"", KEY_COPY_VALUE, value, name));
}
} catch (IllegalArgumentException notValue) {
error(String.format("Invalid %s \"%s\" for label \"%s\": %s", KEY_COPY_VALUE, value, name, notValue.getMessage()));
}
}
label.setCopyValues(copyValues);
label.setCanOverride(rc.getBoolean(LABEL, name, KEY_CAN_OVERRIDE, LabelType.DEF_CAN_OVERRIDE));
List<String> refPatterns = getStringListOrNull(rc, LABEL, name, KEY_BRANCH);
if (refPatterns == null) {
label.setRefPatterns(null);
} else {
for (String pattern : refPatterns) {
if (pattern.startsWith("^")) {
try {
Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
error(String.format("Invalid ref pattern \"%s\" in %s.%s.%s: %s", pattern, LABEL, name, KEY_BRANCH, e.getMessage()));
}
}
}
label.setRefPatterns(ImmutableList.copyOf(refPatterns));
}
labelSections.put(name, label.build());
}
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class LabelDefinitionJson method format.
public static LabelDefinitionInfo format(Project.NameKey projectName, LabelType labelType) {
LabelDefinitionInfo label = new LabelDefinitionInfo();
label.name = labelType.getName();
label.description = labelType.getDescription().orElse(null);
label.projectName = projectName.get();
label.function = labelType.getFunction().getFunctionName();
label.values = labelType.getValues().stream().collect(toMap(LabelValue::formatValue, LabelValue::getText));
label.defaultValue = labelType.getDefaultValue();
label.branches = labelType.getRefPatterns() != null ? labelType.getRefPatterns() : null;
label.canOverride = toBoolean(labelType.isCanOverride());
label.copyCondition = labelType.getCopyCondition().orElse(null);
label.copyAnyScore = toBoolean(labelType.isCopyAnyScore());
label.copyMinScore = toBoolean(labelType.isCopyMinScore());
label.copyMaxScore = toBoolean(labelType.isCopyMaxScore());
label.copyAllScoresIfListOfFilesDidNotChange = toBoolean(labelType.isCopyAllScoresIfListOfFilesDidNotChange());
label.copyAllScoresIfNoChange = toBoolean(labelType.isCopyAllScoresIfNoChange());
label.copyAllScoresIfNoCodeChange = toBoolean(labelType.isCopyAllScoresIfNoCodeChange());
label.copyAllScoresOnTrivialRebase = toBoolean(labelType.isCopyAllScoresOnTrivialRebase());
label.copyAllScoresOnMergeFirstParentUpdate = toBoolean(labelType.isCopyAllScoresOnMergeFirstParentUpdate());
label.copyValues = labelType.getCopyValues().isEmpty() ? null : labelType.getCopyValues();
label.allowPostSubmit = toBoolean(labelType.isAllowPostSubmit());
label.ignoreSelfApproval = toBoolean(labelType.isIgnoreSelfApproval());
return label;
}
Aggregations