in src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/config/ConfigTranslator.java [131:190]
private void applyLabelsTo(
Map<String, LabelDefinition> labels,
ProjectConfig projectConfig,
PluginConfig hostPluginConfig)
throws BadRequestException, IOException {
if (labels.isEmpty()) {
return;
}
for (Map.Entry<String, LabelDefinition> entry : labels.entrySet()) {
if (!projectConfig.getLabelSections().containsKey(entry.getKey())) {
// The current project does not have this label. Try to copy it down from the inherited
// labels to be able to modify it locally.
Map<String, LabelType> copiedLabelTypes = projectConfig.getLabelSections();
ProjectState projectState =
projectCache
.get(projectConfig.getName())
.orElseThrow(illegalState(projectConfig.getName()));
projectState.getLabelTypes().getLabelTypes().stream()
.filter(l -> l.getName().equals(entry.getKey()))
.filter(l -> l.isCanOverride())
.forEach(l -> copiedLabelTypes.put(l.getName(), l));
}
String label = entry.getKey();
LabelDefinition definition = entry.getValue();
if (projectConfig.getLabelSections().get(label) == null) {
throw new BadRequestException(
"The label " + label + " does not exist. You can't change its config.");
}
if (definition.getFunction().isPresent()) {
Set<String> disallowedLabelFunctions =
ImmutableSet.copyOf(
hostPluginConfig.getStringList("disallowedLabelFunctions-" + label));
LabelFunction function = definition.getFunction().get();
if (disallowedLabelFunctions.contains(function.getFunctionName())) {
throw new BadRequestException(function.getFunctionName() + " disallowed");
}
}
projectConfig.updateLabelType(
label,
labelType -> {
if (definition.ignoreSelfApproval != null) {
labelType.setIgnoreSelfApproval(definition.ignoreSelfApproval);
}
if (definition.getFunction().isPresent()) {
labelType.setFunction(definition.getFunction().get());
}
});
if (definition.copyScoreRules != null) {
LabelType.Builder builder = projectConfig.getLabelSections().get(label).toBuilder();
Set<String> disallowedCopyScoreRules =
ImmutableSet.copyOf(
hostPluginConfig.getStringList("disallowedCopyScoreRules-" + label));
applyCopyScoreRulesTo(definition.copyScoreRules, disallowedCopyScoreRules, builder);
projectConfig.upsertLabelType(builder.build());
}
}
}