Search in sources :

Example 6 with LabelValue

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;
}
Also used : LabelValue(com.google.gerrit.common.data.LabelValue) LabelType(com.google.gerrit.common.data.LabelType)

Example 7 with LabelValue

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();
}
Also used : LabelTypes(com.google.gerrit.common.data.LabelTypes) LabelValue(com.google.gerrit.common.data.LabelValue) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) SubmitRecord(com.google.gerrit.common.data.SubmitRecord) LabelType(com.google.gerrit.common.data.LabelType) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) Collection(java.util.Collection) LabelPermission(com.google.gerrit.server.permissions.LabelPermission) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 8 with LabelValue

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();
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelValue(com.google.gerrit.common.data.LabelValue) LabelType(com.google.gerrit.common.data.LabelType) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 9 with LabelValue

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();
}
Also used : LabelValue(com.google.gerrit.common.data.LabelValue) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) LabelType(com.google.gerrit.common.data.LabelType) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 10 with LabelValue

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());
    }
}
Also used : LabelValue(com.google.gerrit.common.data.LabelValue)

Aggregations

LabelValue (com.google.gerrit.common.data.LabelValue)10 LabelType (com.google.gerrit.common.data.LabelType)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 LabelTypes (com.google.gerrit.common.data.LabelTypes)1 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 Account (com.google.gerrit.reviewdb.client.Account)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 ChangeIndexCollection (com.google.gerrit.server.index.change.ChangeIndexCollection)1 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)1 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)1 ProjectControl (com.google.gerrit.server.project.ProjectControl)1 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)1 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 TreeMap (java.util.TreeMap)1