Search in sources :

Example 21 with SubmitRecord

use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval.

@Test
public void defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval() throws Exception {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.NOT_READY, Arrays.asList(createLabel("ISA-Label", Label.Status.NEED)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "ISA-Label", /* submitExpression= */
    "label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.UNSATISFIED, SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 22 with SubmitRecord

use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval.

@Test
public void defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval() throws Exception {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.OK, Arrays.asList(createLabel("ISA-Label", Label.Status.OK)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "ISA-Label", /* submitExpression= */
    "label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.SATISFIED, SubmitRequirementExpressionResult.Status.PASS);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 23 with SubmitRecord

use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.

the class LabelsJson method initLabels.

private Map<String, LabelWithStatus> initLabels(AccountLoader accountLoader, ChangeData cd, LabelTypes labelTypes, boolean standard) {
    Map<String, LabelWithStatus> labels = new TreeMap<>(labelTypes.nameComparator());
    for (SubmitRecord rec : submitRecords(cd)) {
        if (rec.labels == null) {
            continue;
        }
        for (SubmitRecord.Label r : rec.labels) {
            LabelWithStatus p = labels.get(r.label);
            if (p == null || p.status().compareTo(r.status) < 0) {
                LabelInfo n = new LabelInfo();
                if (standard) {
                    switch(r.status) {
                        case OK:
                            n.approved = accountLoader.get(r.appliedBy);
                            break;
                        case REJECT:
                            n.rejected = accountLoader.get(r.appliedBy);
                            n.blocking = true;
                            break;
                        case IMPOSSIBLE:
                        case MAY:
                        case NEED:
                        default:
                            break;
                    }
                }
                n.optional = r.status == SubmitRecord.Label.Status.MAY ? true : null;
                labels.put(r.label, LabelWithStatus.create(n, r.status));
            }
        }
    }
    setLabelsDescription(labels, labelTypes);
    return labels;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) TreeMap(java.util.TreeMap)

Example 24 with SubmitRecord

use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.

the class ReviewerJson method format.

public ReviewerInfo format(ReviewerInfo out, Account.Id reviewerAccountId, ChangeData cd, Iterable<PatchSetApproval> approvals) throws PermissionBackendException {
    LabelTypes labelTypes = cd.getLabelTypes();
    out.approvals = new TreeMap<>(labelTypes.nameComparator());
    for (PatchSetApproval ca : approvals) {
        Optional<LabelType> at = labelTypes.byLabel(ca.labelId());
        at.ifPresent(lt -> out.approvals.put(lt.getName(), formatValue(ca.value())));
    }
    // Add dummy approvals for all permitted labels for the user even if they
    // do not exist in the DB.
    PatchSet ps = cd.currentPatchSet();
    if (ps != null) {
        PermissionBackend.ForChange perm = permissionBackend.absentUser(reviewerAccountId).change(cd);
        for (SubmitRecord rec : cd.submitRecords(SubmitRuleOptions.defaults())) {
            if (rec.labels == null) {
                continue;
            }
            for (SubmitRecord.Label label : rec.labels) {
                String name = label.label;
                Optional<LabelType> type = labelTypes.byLabel(name);
                if (out.approvals.containsKey(name) || !type.isPresent()) {
                    continue;
                }
                if (perm.test(new LabelPermission(type.get()))) {
                    out.approvals.put(name, formatValue((short) 0));
                }
            }
        }
    }
    if (out.approvals.isEmpty()) {
        out.approvals = null;
    }
    return out;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) LabelTypes(com.google.gerrit.entities.LabelTypes) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) LabelType(com.google.gerrit.entities.LabelType) PatchSet(com.google.gerrit.entities.PatchSet) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) LabelPermission(com.google.gerrit.server.permissions.LabelPermission)

Example 25 with SubmitRecord

use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.

the class ChangeField method formatSubmitRecordValues.

@VisibleForTesting
static List<String> formatSubmitRecordValues(List<SubmitRecord> records, Account.Id changeOwner) {
    List<String> result = new ArrayList<>();
    for (SubmitRecord rec : records) {
        result.add(rec.status.name());
        if (rec.labels == null) {
            continue;
        }
        for (SubmitRecord.Label label : rec.labels) {
            String sl = label.status.toString() + ',' + label.label.toLowerCase();
            result.add(sl);
            String slc = sl + ',';
            if (label.appliedBy != null) {
                result.add(slc + label.appliedBy.get());
                if (label.appliedBy.equals(changeOwner)) {
                    result.add(slc + ChangeQueryBuilder.OWNER_ACCOUNT_ID.get());
                }
            }
        }
    }
    return result;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SubmitRecord (com.google.gerrit.entities.SubmitRecord)49 Test (org.junit.Test)24 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)14 Change (com.google.gerrit.entities.Change)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelType (com.google.gerrit.entities.LabelType)6 List (java.util.List)6 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Inject (com.google.inject.Inject)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 ImmutableList (com.google.common.collect.ImmutableList)4 FluentLogger (com.google.common.flogger.FluentLogger)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 LabelFunction (com.google.gerrit.entities.LabelFunction)4 PatchSet (com.google.gerrit.entities.PatchSet)4 Project (com.google.gerrit.entities.Project)4 StorageException (com.google.gerrit.exceptions.StorageException)4 DefaultSubmitRule (com.google.gerrit.server.rules.DefaultSubmitRule)4