Search in sources :

Example 6 with SubmitRecord

use of com.google.gerrit.common.data.SubmitRecord in project gerrit by GerritCodeReview.

the class MergeOp method bypassSubmitRules.

private void bypassSubmitRules(ChangeSet cs) {
    checkArgument(!cs.furtherHiddenChanges(), "cannot bypass submit rules for topic with hidden change");
    for (ChangeData cd : cs.changes()) {
        List<SubmitRecord> records;
        try {
            records = new ArrayList<>(getSubmitRecords(cd));
        } catch (OrmException e) {
            log.warn("Error checking submit rules for change " + cd.getId(), e);
            records = new ArrayList<>(1);
        }
        SubmitRecord forced = new SubmitRecord();
        forced.status = SubmitRecord.Status.FORCED;
        records.add(forced);
        cd.setSubmitRecords(SUBMIT_RULE_OPTIONS, records);
    }
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 7 with SubmitRecord

use of com.google.gerrit.common.data.SubmitRecord in project gerrit by GerritCodeReview.

the class ChangeData method submitRecords.

public List<SubmitRecord> submitRecords(SubmitRuleOptions options) throws OrmException {
    List<SubmitRecord> records = submitRecords.get(options);
    if (records == null) {
        if (!lazyLoad) {
            return Collections.emptyList();
        }
        records = new SubmitRuleEvaluator(this).setOptions(options).evaluate();
        submitRecords.put(options, records);
    }
    return records;
}
Also used : SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) SubmitRecord(com.google.gerrit.common.data.SubmitRecord)

Example 8 with SubmitRecord

use of com.google.gerrit.common.data.SubmitRecord in project gerrit by GerritCodeReview.

the class SubmitRuleEvaluator method evaluate.

/**
   * Evaluate the submit rules.
   *
   * @return List of {@link SubmitRecord} objects returned from the evaluated rules, including any
   *     errors.
   */
public List<SubmitRecord> evaluate() {
    initOptions();
    Change c = control.getChange();
    if (!opts.allowClosed() && c.getStatus().isClosed()) {
        SubmitRecord rec = new SubmitRecord();
        rec.status = SubmitRecord.Status.CLOSED;
        return Collections.singletonList(rec);
    }
    if (!opts.allowDraft()) {
        try {
            initPatchSet();
        } catch (OrmException e) {
            return ruleError("Error looking up patch set " + control.getChange().currentPatchSetId(), e);
        }
        if (c.getStatus() == Change.Status.DRAFT || patchSet.isDraft()) {
            return cannotSubmitDraft();
        }
    }
    List<Term> results;
    try {
        results = evaluateImpl("locate_submit_rule", "can_submit", "locate_submit_filter", "filter_submit_results", control.getUser());
    } catch (RuleEvalException e) {
        return ruleError(e.getMessage(), e);
    }
    if (results.isEmpty()) {
        // whether or not that is actually possible given the permissions.
        return ruleError(String.format("Submit rule '%s' for change %s of %s has no solution.", getSubmitRuleName(), cd.getId(), getProjectName()));
    }
    return resultsToSubmitRecord(getSubmitRule(), results);
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 9 with SubmitRecord

use of com.google.gerrit.common.data.SubmitRecord in project gerrit by GerritCodeReview.

the class SubmitRuleEvaluator method createRuleError.

public static List<SubmitRecord> createRuleError(String err) {
    SubmitRecord rec = new SubmitRecord();
    rec.status = SubmitRecord.Status.RULE_ERROR;
    rec.errorMessage = err;
    return Collections.singletonList(rec);
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord)

Example 10 with SubmitRecord

use of com.google.gerrit.common.data.SubmitRecord in project gerrit by GerritCodeReview.

the class ChangeJson method initLabels.

private Map<String, LabelWithStatus> initLabels(ChangeData cd, LabelTypes labelTypes, boolean standard) throws OrmException {
    // Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
    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));
            }
        }
    }
    return labels;
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) TreeMap(java.util.TreeMap)

Aggregations

SubmitRecord (com.google.gerrit.common.data.SubmitRecord)19 Change (com.google.gerrit.reviewdb.client.Change)3 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)3 SubmitRuleEvaluator (com.google.gerrit.server.project.SubmitRuleEvaluator)3 OrmException (com.google.gwtorm.server.OrmException)3 ArrayList (java.util.ArrayList)3 LabelType (com.google.gerrit.common.data.LabelType)2 LabelTypes (com.google.gerrit.common.data.LabelTypes)2 Account (com.google.gerrit.reviewdb.client.Account)2 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)2 RequestId (com.google.gerrit.server.util.RequestId)2 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)2 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)2 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)2 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)2 Term (com.googlecode.prolog_cafe.lang.Term)2 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2