use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class ProjectJson method format.
public ProjectInfo format(ProjectState projectState) {
ProjectInfo info = format(projectState.getProject());
info.labels = new HashMap<>();
for (LabelType t : projectState.getLabelTypes().getLabelTypes()) {
LabelTypeInfo labelInfo = new LabelTypeInfo();
labelInfo.values = t.getValues().stream().collect(toMap(LabelValue::formatValue, LabelValue::getText, (v1, v2) -> {
logger.atSevere().log("Duplicate values for project: %s, label: %s found: '%s':'%s'", projectState.getName(), t.getName(), v1, v2);
return v1;
}));
labelInfo.defaultValue = t.getDefaultValue();
info.labels.put(t.getName(), labelInfo);
}
return info;
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class MergedSender method format.
private String format(String type, Table<Account.Id, String, PatchSetApproval> approvals) {
StringBuilder txt = new StringBuilder();
if (approvals.isEmpty()) {
return "";
}
txt.append(type).append(":\n");
for (Account.Id id : approvals.rowKeySet()) {
txt.append(" ");
txt.append(getNameFor(id));
txt.append(": ");
boolean first = true;
for (LabelType lt : labelTypes.getLabelTypes()) {
PatchSetApproval ca = approvals.get(id, lt.getName());
if (ca == null) {
continue;
}
if (first) {
first = false;
} else {
txt.append("; ");
}
LabelValue v = lt.getValue(ca);
if (v != null) {
txt.append(v.getText());
} else {
txt.append(lt.getName());
txt.append('=');
txt.append(LabelValue.formatValue(ca.value()));
}
}
txt.append('\n');
}
txt.append('\n');
return txt.toString();
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class CreateLabel method createLabel.
/**
* Creates a new label.
*
* @param config the project config
* @param label the name of the new label
* @param input the input that describes the new label
* @return the created label type
* @throws BadRequestException if there was invalid data in the input
* @throws ResourceConflictException if the label cannot be created due to a conflict
*/
public LabelType createLabel(ProjectConfig config, String label, LabelDefinitionInput input) throws BadRequestException, ResourceConflictException {
if (config.getLabelSections().containsKey(label)) {
throw new ResourceConflictException(String.format("label %s already exists", label));
}
for (String labelName : config.getLabelSections().keySet()) {
if (labelName.equalsIgnoreCase(label)) {
throw new ResourceConflictException(String.format("label %s conflicts with existing label %s", label, labelName));
}
}
if (input.values == null || input.values.isEmpty()) {
throw new BadRequestException("values are required");
}
try {
LabelType.checkName(label);
} catch (IllegalArgumentException e) {
throw new BadRequestException("invalid name: " + label, e);
}
List<LabelValue> values = LabelDefinitionInputParser.parseValues(input.values);
LabelType.Builder labelType = LabelType.builder(LabelType.checkName(label), values);
if (input.description != null) {
String description = Strings.emptyToNull(input.description.trim());
labelType.setDescription(Optional.ofNullable(description));
}
if (input.function != null && !input.function.trim().isEmpty()) {
labelType.setFunction(LabelDefinitionInputParser.parseFunction(input.function));
} else {
labelType.setFunction(LabelFunction.MAX_WITH_BLOCK);
}
if (input.defaultValue != null) {
labelType.setDefaultValue(LabelDefinitionInputParser.parseDefaultValue(labelType, input.defaultValue));
}
if (input.branches != null) {
labelType.setRefPatterns(LabelDefinitionInputParser.parseBranches(input.branches));
}
if (input.canOverride != null) {
labelType.setCanOverride(input.canOverride);
}
if (input.copyAnyScore != null) {
labelType.setCopyAnyScore(input.copyAnyScore);
}
if (input.copyCondition != null) {
try {
approvalQueryBuilder.parse(input.copyCondition);
} catch (QueryParseException e) {
throw new BadRequestException("unable to parse copy condition. got: " + input.copyCondition + ". " + e.getMessage(), e);
}
if (Boolean.TRUE.equals(input.unsetCopyCondition)) {
throw new BadRequestException("can't set and unset copyCondition in the same request");
}
labelType.setCopyCondition(Strings.emptyToNull(input.copyCondition));
}
if (Boolean.TRUE.equals(input.unsetCopyCondition)) {
labelType.setCopyCondition(null);
}
if (input.copyMinScore != null) {
labelType.setCopyMinScore(input.copyMinScore);
}
if (input.copyMaxScore != null) {
labelType.setCopyMaxScore(input.copyMaxScore);
}
if (input.copyAllScoresIfListOfFilesDidNotChange != null) {
labelType.setCopyAllScoresIfListOfFilesDidNotChange(input.copyAllScoresIfListOfFilesDidNotChange);
}
if (input.copyAllScoresIfNoChange != null) {
labelType.setCopyAllScoresIfNoChange(input.copyAllScoresIfNoChange);
}
if (input.copyAllScoresIfNoCodeChange != null) {
labelType.setCopyAllScoresIfNoCodeChange(input.copyAllScoresIfNoCodeChange);
}
if (input.copyAllScoresOnTrivialRebase != null) {
labelType.setCopyAllScoresOnTrivialRebase(input.copyAllScoresOnTrivialRebase);
}
if (input.copyAllScoresOnMergeFirstParentUpdate != null) {
labelType.setCopyAllScoresOnMergeFirstParentUpdate(input.copyAllScoresOnMergeFirstParentUpdate);
}
if (input.copyValues != null) {
labelType.setCopyValues(input.copyValues);
}
if (input.allowPostSubmit != null) {
labelType.setAllowPostSubmit(input.allowPostSubmit);
}
if (input.ignoreSelfApproval != null) {
labelType.setIgnoreSelfApproval(input.ignoreSelfApproval);
}
LabelType lt = labelType.build();
config.upsertLabelType(lt);
return lt;
}
use of com.google.gerrit.entities.LabelValue in project gerrit by GerritCodeReview.
the class LabelValueSerializerTest method roundTrip.
@Test
public void roundTrip() {
LabelValue autoValue = LabelValue.create((short) 123, "Approved!");
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
Aggregations