use of com.google.gerrit.extensions.common.SubmitRecordInfo in project gerrit by GerritCodeReview.
the class ChangeJson method submitRecordToInfo.
private SubmitRecordInfo submitRecordToInfo(SubmitRecord record) {
SubmitRecordInfo info = new SubmitRecordInfo();
if (record.status != null) {
info.status = SubmitRecordInfo.Status.valueOf(record.status.name());
}
info.ruleName = record.ruleName;
info.errorMessage = record.errorMessage;
if (record.labels != null) {
info.labels = new ArrayList<>();
for (SubmitRecord.Label label : record.labels) {
SubmitRecordInfo.Label labelInfo = new SubmitRecordInfo.Label();
labelInfo.label = label.label;
if (label.status != null) {
labelInfo.status = SubmitRecordInfo.Label.Status.valueOf(label.status.name());
}
labelInfo.appliedBy = accountLoader.get(label.appliedBy);
info.labels.add(labelInfo);
}
}
if (record.requirements != null) {
info.requirements = new ArrayList<>();
for (LegacySubmitRequirement requirement : record.requirements) {
info.requirements.add(requirementToInfo(requirement, record.status));
}
}
return info;
}
use of com.google.gerrit.extensions.common.SubmitRecordInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRecords.
@Test
public void submitRecords() throws Exception {
PushOneCommit.Result r = createChange();
TestSubmitRule testSubmitRule = new TestSubmitRule();
try (Registration registration = extensionRegistry.newRegistration().add(testSubmitRule)) {
String changeId = r.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRecords).hasSize(2);
// Check the default submit record for the code-review label
SubmitRecordInfo codeReviewRecord = Iterables.get(change.submitRecords, 0);
assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.NOT_READY);
assertThat(codeReviewRecord.labels).hasSize(1);
SubmitRecordInfo.Label label = Iterables.getOnlyElement(codeReviewRecord.labels);
assertThat(label.label).isEqualTo("Code-Review");
assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.NEED);
assertThat(label.appliedBy).isNull();
// Check the custom test record created by the TestSubmitRule
SubmitRecordInfo testRecord = Iterables.get(change.submitRecords, 1);
assertThat(testRecord.ruleName).isEqualTo("testSubmitRule");
assertThat(testRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
assertThat(testRecord.requirements).containsExactly(new LegacySubmitRequirementInfo("OK", "fallback text", "type"));
assertThat(testRecord.labels).hasSize(1);
SubmitRecordInfo.Label testLabel = Iterables.getOnlyElement(testRecord.labels);
assertThat(testLabel.label).isEqualTo("label");
assertThat(testLabel.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
assertThat(testLabel.appliedBy).isNull();
voteLabel(changeId, "Code-Review", 2);
// Code review record is satisfied after voting +2
change = gApi.changes().id(changeId).get();
assertThat(change.submitRecords).hasSize(2);
codeReviewRecord = Iterables.get(change.submitRecords, 0);
assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
assertThat(codeReviewRecord.labels).hasSize(1);
label = Iterables.getOnlyElement(codeReviewRecord.labels);
assertThat(label.label).isEqualTo("Code-Review");
assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
assertThat(label.appliedBy._accountId).isEqualTo(admin.id().get());
}
}
Aggregations