use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class TestSubmitRule method newSubmitRuleInfo.
private static TestSubmitRuleInfo newSubmitRuleInfo(SubmitRecord r, AccountLoader accounts) {
TestSubmitRuleInfo info = new TestSubmitRuleInfo();
info.status = r.status.name();
info.errorMessage = r.errorMessage;
if (r.labels != null) {
for (SubmitRecord.Label n : r.labels) {
AccountInfo who = n.appliedBy != null ? accounts.get(n.appliedBy) : new AccountInfo(null);
label(info, n, who);
}
}
return info;
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class PrologRuleEvaluator method resultsToSubmitRecord.
/**
* Convert the results from Prolog Cafe's format to Gerrit's common format.
*
* <p>can_submit/1 terminates when an ok(P) record is found. Therefore walk the results backwards,
* using only that ok(P) record if it exists. This skips partial results that occur early in the
* output. Later after the loop the out collection is reversed to restore it to the original
* ordering.
*/
public SubmitRecord resultsToSubmitRecord(Term submitRule, List<Term> results) {
checkState(!results.isEmpty(), "the list of Prolog terms must not be empty");
SubmitRecord resultSubmitRecord = new SubmitRecord();
resultSubmitRecord.labels = new ArrayList<>();
for (int resultIdx = results.size() - 1; 0 <= resultIdx; resultIdx--) {
Term submitRecord = results.get(resultIdx);
if (!(submitRecord instanceof StructureTerm) || 1 != submitRecord.arity()) {
return invalidResult(submitRule, submitRecord);
}
if (!"ok".equals(submitRecord.name()) && !"not_ready".equals(submitRecord.name())) {
return invalidResult(submitRule, submitRecord);
}
// the change to be submittable when at least one result is OK.
if ("ok".equals(submitRecord.name())) {
resultSubmitRecord.status = SubmitRecord.Status.OK;
} else if ("not_ready".equals(submitRecord.name()) && resultSubmitRecord.status == null) {
resultSubmitRecord.status = SubmitRecord.Status.NOT_READY;
}
// Unpack the one argument. This should also be a structure with one
// argument per label that needs to be reported on to the caller.
//
submitRecord = submitRecord.arg(0);
if (!(submitRecord instanceof StructureTerm)) {
return invalidResult(submitRule, submitRecord);
}
for (Term state : ((StructureTerm) submitRecord).args()) {
if (!(state instanceof StructureTerm) || 2 != state.arity() || !"label".equals(state.name())) {
return invalidResult(submitRule, submitRecord);
}
SubmitRecord.Label lbl = new SubmitRecord.Label();
resultSubmitRecord.labels.add(lbl);
lbl.label = checkLabelName(state.arg(0).name());
Term status = state.arg(1);
try {
if ("ok".equals(status.name())) {
lbl.status = SubmitRecord.Label.Status.OK;
appliedBy(lbl, status);
} else if ("reject".equals(status.name())) {
lbl.status = SubmitRecord.Label.Status.REJECT;
appliedBy(lbl, status);
} else if ("need".equals(status.name())) {
lbl.status = SubmitRecord.Label.Status.NEED;
} else if ("may".equals(status.name())) {
lbl.status = SubmitRecord.Label.Status.MAY;
} else if ("impossible".equals(status.name())) {
lbl.status = SubmitRecord.Label.Status.IMPOSSIBLE;
} else {
return invalidResult(submitRule, submitRecord);
}
} catch (UserTermExpected e) {
return invalidResult(submitRule, submitRecord, e.getMessage());
}
}
if (resultSubmitRecord.status == SubmitRecord.Status.OK) {
break;
}
}
Collections.reverse(resultSubmitRecord.labels);
return resultSubmitRecord;
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class ChangeNotesParser method parseSubmitRecords.
private void parseSubmitRecords(List<String> lines) throws ConfigInvalidException {
SubmitRecord rec = null;
for (String line : lines) {
int c = line.indexOf(": ");
if (c < 0) {
rec = new SubmitRecord();
submitRecords.add(rec);
int s = line.indexOf(' ');
String statusStr = s >= 0 ? line.substring(0, s) : line;
rec.status = Enums.getIfPresent(SubmitRecord.Status.class, statusStr).orNull();
checkFooter(rec.status != null, FOOTER_SUBMITTED_WITH, line);
if (s >= 0) {
rec.errorMessage = line.substring(s);
}
} else {
checkFooter(rec != null, FOOTER_SUBMITTED_WITH, line);
if (line.startsWith("Rule-Name: ")) {
String ruleName = RULE_SPLITTER.splitToList(line).get(1);
rec.ruleName = ruleName;
continue;
}
SubmitRecord.Label label = new SubmitRecord.Label();
if (rec.labels == null) {
rec.labels = new ArrayList<>();
}
rec.labels.add(label);
label.status = Enums.getIfPresent(SubmitRecord.Label.Status.class, line.substring(0, c)).orNull();
checkFooter(label.status != null, FOOTER_SUBMITTED_WITH, line);
int c2 = line.indexOf(": ", c + 2);
if (c2 >= 0) {
label.label = line.substring(c + 2, c2);
PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(c2 + 2));
checkFooter(ident != null, FOOTER_SUBMITTED_WITH, line);
label.appliedBy = parseIdent(ident);
} else {
label.label = line.substring(c + 2);
}
}
}
}
use of com.google.gerrit.entities.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) {
la.by = asAccountAttribute(lbl.appliedBy);
}
sa.labels.add(la);
}
}
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class EventFactory method addSubmitRecords.
/**
* Add submitRecords to an existing {@link ChangeAttribute}.
*/
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);
addSubmitRecordRequirements(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;
}
}
Aggregations