Search in sources :

Example 1 with SubmitRecordInfo

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;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo)

Example 2 with SubmitRecordInfo

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());
    }
}
Also used : LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

SubmitRecordInfo (com.google.gerrit.extensions.common.SubmitRecordInfo)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 LegacySubmitRequirement (com.google.gerrit.entities.LegacySubmitRequirement)1 SubmitRecord (com.google.gerrit.entities.SubmitRecord)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 LegacySubmitRequirementInfo (com.google.gerrit.extensions.common.LegacySubmitRequirementInfo)1 Test (org.junit.Test)1