use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class PrologRuleEvaluator method createRuleError.
private static SubmitRecord createRuleError(String err) {
SubmitRecord rec = new SubmitRecord();
rec.status = SubmitRecord.Status.RULE_ERROR;
rec.errorMessage = err;
return rec;
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class SubmitRuleIT method submitRecordsForClosedChanges_parsedBackByDefault.
@Test
public void submitRecordsForClosedChanges_parsedBackByDefault() throws Exception {
SubmitRuleEvaluator submitRuleEvaluator = submitRuleEvaluatorFactory.create(SubmitRuleOptions.defaults());
PushOneCommit.Result r = createChange();
approve(r.getChangeId());
List<SubmitRecord> recordsBeforeSubmission = submitRuleEvaluator.evaluate(r.getChange());
assertThat(recordsBeforeSubmission.stream().map(record -> record.ruleName).collect(Collectors.toList())).containsExactly(DefaultSubmitRule.RULE_NAME);
gApi.changes().id(r.getChangeId()).current().submit();
// Add a new label that blocks submission if not granted. In case we reevaluate the rules,
// this would show up as blocking submission.
setupCustomBlockingLabel();
List<SubmitRecord> recordsAfterSubmission = submitRuleEvaluator.evaluate(r.getChange());
recordsBeforeSubmission.forEach(// Set status to closed
sr -> sr.status = SubmitRecord.Status.CLOSED);
assertThat(recordsBeforeSubmission).isEqualTo(recordsAfterSubmission);
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class IgnoreSelfApprovalRuleIT method blocksWhenUploaderIsOnlyApprover.
@Test
public void blocksWhenUploaderIsOnlyApprover() throws Exception {
enableRule(LabelId.CODE_REVIEW, true);
PushOneCommit.Result r = createChange();
approve(r.getChangeId());
Optional<SubmitRecord> submitRecord = rule.evaluate(r.getChange());
assertThat(submitRecord).isPresent();
SubmitRecord result = submitRecord.get();
assertThat(result.status).isEqualTo(SubmitRecord.Status.NOT_READY);
assertThat(result.labels).isNotEmpty();
assertThat(result.requirements).containsExactly(LegacySubmitRequirement.builder().setFallbackText("Approval from non-uploader required").setType("non_uploader_approval").build());
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class IgnoreSelfApprovalRuleIT method allowsSubmissionWhenChangeHasNonUploaderApproval.
@Test
public void allowsSubmissionWhenChangeHasNonUploaderApproval() throws Exception {
enableRule(LabelId.CODE_REVIEW, true);
// Create change as user
TestRepository<InMemoryRepository> userTestRepo = cloneProject(project, user);
PushOneCommit push = pushFactory.create(user.newIdent(), userTestRepo);
PushOneCommit.Result r = push.to("refs/for/master");
// Approve as admin
approve(r.getChangeId());
Optional<SubmitRecord> submitRecord = rule.evaluate(r.getChange());
assertThat(submitRecord).isEmpty();
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixSubmittedWithFooterIdent.
@Test
public void fixSubmittedWithFooterIdent() throws Exception {
Change c = newChange();
ChangeUpdate preSubmitUpdate = newUpdate(c, changeOwner);
preSubmitUpdate.setChangeMessage("Per-submit update");
preSubmitUpdate.commit();
String otherUserIdentToFix = getAccountIdentToFix(otherUser.getAccount());
String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
RevCommit invalidUpdateCommit = writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, "Label: SUBM=+1", "Submission-id: 5271-1496917120975-10a10df9", "Submitted-with: NOT_READY", "Submitted-with: NEED: Code-Review: " + otherUserIdentToFix, "Submitted-with: OK: Code-Style", "Submitted-with: OK: Verified: " + changeOwnerIdentToFix, "Submitted-with: FORCED with error"), getAuthorIdent(changeOwner.getAccount()));
ChangeUpdate postSubmitUpdate = newUpdate(c, changeOwner);
postSubmitUpdate.setChangeMessage("Per-submit update");
postSubmitUpdate.commit();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
int invalidCommitIndex = commitsBeforeRewrite.indexOf(invalidUpdateCommit);
ChangeNotes notesBeforeRewrite = newNotes(c);
RunOptions options = new RunOptions();
options.dryRun = false;
BackfillResult result = rewriter.backfillProject(project, repo, options);
assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
ChangeNotes notesAfterRewrite = newNotes(c);
ImmutableList<SubmitRecord> expectedRecords = ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(CODE_REVIEW, "NEED", otherUserId), submitLabel("Code-Style", "OK", null), submitLabel(VERIFIED, "OK", changeOwner.getAccountId())), submitRecord("FORCED", " with error"));
assertThat(notesBeforeRewrite.getSubmitRecords()).isEqualTo(expectedRecords);
assertThat(notesAfterRewrite.getSubmitRecords()).isEqualTo(expectedRecords);
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, ImmutableList.of(invalidCommitIndex));
assertFixedCommits(ImmutableList.of(invalidUpdateCommit.getId()), result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -10 +10 @@\n" + "-Submitted-with: NEED: Code-Review: Other Account <2@gerrit>\n" + "+Submitted-with: NEED: Code-Review: Gerrit User 2 <2@gerrit>\n" + "@@ -12 +12 @@\n" + "-Submitted-with: OK: Verified: Change Owner <1@gerrit>\n" + "+Submitted-with: OK: Verified: Gerrit User 1 <1@gerrit>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Aggregations