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