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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations