use of com.google.gerrit.common.data.LabelValue in project gerrit by GerritCodeReview.
the class AllProjectsCreator method initCodeReviewLabel.
public static LabelType initCodeReviewLabel(ProjectConfig c) {
LabelType type = new LabelType("Code-Review", ImmutableList.of(new LabelValue((short) 2, "Looks good to me, approved"), new LabelValue((short) 1, "Looks good to me, but someone else must approve"), new LabelValue((short) 0, "No score"), new LabelValue((short) -1, "I would prefer this is not merged as is"), new LabelValue((short) -2, "This shall not be merged")));
type.setCopyMinScore(true);
type.setCopyAllScoresOnTrivialRebase(true);
c.getLabelSections().put(type.getName(), type);
return type;
}
use of com.google.gerrit.common.data.LabelValue in project gerrit by GerritCodeReview.
the class ChangeJson method permittedLabels.
private Map<String, Collection<String>> permittedLabels(PermissionBackend.ForChange perm, ChangeData cd) throws OrmException, PermissionBackendException {
boolean isMerged = cd.change().getStatus() == Change.Status.MERGED;
LabelTypes labelTypes = cd.getLabelTypes();
Map<String, LabelType> toCheck = new HashMap<>();
for (SubmitRecord rec : submitRecords(cd)) {
if (rec.labels != null) {
for (SubmitRecord.Label r : rec.labels) {
LabelType type = labelTypes.byLabel(r.label);
if (type != null && (!isMerged || type.allowPostSubmit())) {
toCheck.put(type.getName(), type);
}
}
}
}
Map<String, Short> labels = null;
Set<LabelPermission.WithValue> can = perm.testLabels(toCheck.values());
SetMultimap<String, String> permitted = LinkedHashMultimap.create();
for (SubmitRecord rec : submitRecords(cd)) {
if (rec.labels == null) {
continue;
}
for (SubmitRecord.Label r : rec.labels) {
LabelType type = labelTypes.byLabel(r.label);
if (type == null || (isMerged && !type.allowPostSubmit())) {
continue;
}
for (LabelValue v : type.getValues()) {
boolean ok = can.contains(new LabelPermission.WithValue(type, v));
if (isMerged) {
if (labels == null) {
labels = currentLabels(perm, cd);
}
short prev = labels.getOrDefault(type.getName(), (short) 0);
ok &= v.getValue() >= prev;
}
if (ok) {
permitted.put(r.label, v.formatValue());
}
}
}
}
List<String> toClear = Lists.newArrayListWithCapacity(permitted.keySet().size());
for (Map.Entry<String, Collection<String>> e : permitted.asMap().entrySet()) {
if (isOnlyZero(e.getValue())) {
toClear.add(e.getKey());
}
}
for (String label : toClear) {
permitted.removeAll(label);
}
return permitted.asMap();
}
use of com.google.gerrit.common.data.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.getValue()));
}
}
txt.append('\n');
}
txt.append('\n');
return txt.toString();
}
use of com.google.gerrit.common.data.LabelValue in project gerrit by GerritCodeReview.
the class ReviewCommand method parseCommandLine.
@Override
protected void parseCommandLine() throws UnloggedFailure {
optionList = new ArrayList<>();
customLabels = new HashMap<>();
ProjectControl allProjectsControl;
try {
allProjectsControl = projectControlFactory.controlFor(allProjects);
} catch (NoSuchProjectException e) {
throw die("missing " + allProjects.get());
}
for (LabelType type : allProjectsControl.getLabelTypes().getLabelTypes()) {
StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
for (LabelValue v : type.getValues()) {
usage.append(v.format()).append("\n");
}
final String name = "--" + type.getName().toLowerCase();
optionList.add(new ApproveOption(name, usage.toString(), type));
}
super.parseCommandLine();
}
use of com.google.gerrit.common.data.LabelValue in project gerrit by GerritCodeReview.
the class LabelNormalizer method applyTypeFloor.
private void applyTypeFloor(LabelType lt, PatchSetApproval a) {
LabelValue atMin = lt.getMin();
if (atMin != null && a.getValue() < atMin.getValue()) {
a.setValue(atMin.getValue());
}
LabelValue atMax = lt.getMax();
if (atMax != null && a.getValue() > atMax.getValue()) {
a.setValue(atMax.getValue());
}
}
Aggregations