Search in sources :

Example 16 with SubmitRecord

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

the class AbstractChangeNotesTest method submitRecord.

protected static SubmitRecord submitRecord(String status, String errorMessage, SubmitRecord.Label... labels) {
    SubmitRecord rec = new SubmitRecord();
    rec.status = SubmitRecord.Status.valueOf(status);
    rec.errorMessage = errorMessage;
    if (labels.length > 0) {
        rec.labels = ImmutableList.copyOf(labels);
    }
    return rec;
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord)

Example 17 with SubmitRecord

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

the class MergeOp method checkSubmitRule.

public static void checkSubmitRule(ChangeData cd) throws ResourceConflictException, OrmException {
    PatchSet patchSet = cd.currentPatchSet();
    if (patchSet == null) {
        throw new ResourceConflictException("missing current patch set for change " + cd.getId());
    }
    List<SubmitRecord> results = getSubmitRecords(cd);
    if (SubmitRecord.findOkRecord(results).isPresent()) {
        // Rules supplied a valid solution.
        return;
    } else if (results.isEmpty()) {
        throw new IllegalStateException(String.format("SubmitRuleEvaluator.evaluate for change %s returned empty list for %s in %s", cd.getId(), patchSet.getId(), cd.change().getProject().get()));
    }
    for (SubmitRecord record : results) {
        switch(record.status) {
            case CLOSED:
                throw new ResourceConflictException("change is closed");
            case RULE_ERROR:
                throw new ResourceConflictException("submit rule error: " + record.errorMessage);
            case NOT_READY:
                throw new ResourceConflictException(describeLabels(cd, record.labels));
            case FORCED:
            case OK:
            default:
                throw new IllegalStateException(String.format("Unexpected SubmitRecord status %s for %s in %s", record.status, patchSet.getId().getId(), cd.change().getProject().get()));
        }
    }
    throw new IllegalStateException();
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 18 with SubmitRecord

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

the class EventFactory method addSubmitRecordLabels.

private void addSubmitRecordLabels(SubmitRecord submitRecord, SubmitRecordAttribute sa) {
    if (submitRecord.labels != null && !submitRecord.labels.isEmpty()) {
        sa.labels = new ArrayList<>();
        for (SubmitRecord.Label lbl : submitRecord.labels) {
            SubmitLabelAttribute la = new SubmitLabelAttribute();
            la.label = lbl.label;
            la.status = lbl.status.name();
            if (lbl.appliedBy != null) {
                Account a = accountCache.get(lbl.appliedBy).getAccount();
                la.by = asAccountAttribute(a);
            }
            sa.labels.add(la);
        }
    }
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) Account(com.google.gerrit.reviewdb.client.Account) SubmitLabelAttribute(com.google.gerrit.server.data.SubmitLabelAttribute)

Example 19 with SubmitRecord

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

the class EventFactory method addSubmitRecords.

/**
   * Add submitRecords to an existing ChangeAttribute.
   *
   * @param ca
   * @param submitRecords
   */
public void addSubmitRecords(ChangeAttribute ca, List<SubmitRecord> submitRecords) {
    ca.submitRecords = new ArrayList<>();
    for (SubmitRecord submitRecord : submitRecords) {
        SubmitRecordAttribute sa = new SubmitRecordAttribute();
        sa.status = submitRecord.status.name();
        if (submitRecord.status != SubmitRecord.Status.RULE_ERROR) {
            addSubmitRecordLabels(submitRecord, sa);
        }
        ca.submitRecords.add(sa);
    }
    // Remove empty lists so a confusing label won't be displayed in the output.
    if (ca.submitRecords.isEmpty()) {
        ca.submitRecords = null;
    }
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) SubmitRecordAttribute(com.google.gerrit.server.data.SubmitRecordAttribute)

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