use of com.google.gerrit.server.rules.DefaultSubmitRule 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.
* @param cd ChangeData to evaluate
*/
public List<SubmitRecord> evaluate(ChangeData cd) {
logger.atFine().log("Evaluate submit rules for change %d (caller: %s)", cd.change().getId().get(), callerFinder.findCallerLazy());
try (Timer0.Context ignored = submitRuleEvaluationLatency.start()) {
Change change;
ProjectState projectState;
try {
change = cd.change();
if (change == null) {
throw new StorageException("Change not found");
}
Project.NameKey name = cd.project();
Optional<ProjectState> projectStateOptional = projectCache.get(name);
if (!projectStateOptional.isPresent()) {
throw new NoSuchProjectException(name);
}
projectState = projectStateOptional.get();
} catch (NoSuchProjectException e) {
throw new IllegalStateException("Unable to find project while evaluating submit rule", e);
}
if (change.isClosed() && (!opts.recomputeOnClosedChanges() || OnlineReindexMode.isActive())) {
return cd.notes().getSubmitRecords().stream().map(r -> {
SubmitRecord record = r.deepCopy();
if (record.status == SubmitRecord.Status.OK) {
// Submit records that were OK when they got merged are CLOSED now.
record.status = SubmitRecord.Status.CLOSED;
}
return record;
}).collect(toImmutableList());
}
// and then we collect the results in one list.
return Streams.stream(submitRules).filter(projectState.hasPrologRules() ? rule -> !(rule.get() instanceof DefaultSubmitRule) : rule -> true).map(c -> c.call(s -> {
Optional<SubmitRecord> record = s.evaluate(cd);
if (record.isPresent() && record.get().ruleName == null) {
// Only back-fill the ruleName if it was not populated by the "submit
// rule".
record.get().ruleName = c.getPluginName() + "~" + s.getClass().getSimpleName();
}
return record;
})).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
}
}
Aggregations