use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixReviewerFooterIdent.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixReviewerFooterIdent() throws Exception {
Change c = newChange();
String reviewerIdentToFix = getAccountIdentToFix(otherUser.getAccount());
ImmutableList<ObjectId> commitsToFix = new ImmutableList.Builder<ObjectId>().add(writeUpdate(RefNames.changeMetaRef(c.getId()), // valid change message that should not be overwritten
getChangeUpdateBody(c, "Removed reviewer <GERRIT_ACCOUNT_1>.", "Reviewer: " + reviewerIdentToFix), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), // valid change message that should not be overwritten
getChangeUpdateBody(c, "Removed cc <GERRIT_ACCOUNT_2> with the following votes:\n\n * Code-Review+2 by <GERRIT_ACCOUNT_2>", "CC: " + reviewerIdentToFix), getAuthorIdent(otherUser.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Removed cc", "Removed: " + reviewerIdentToFix), getAuthorIdent(changeOwner.getAccount()))).build();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
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()));
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<ReviewerStatusUpdate> expectedReviewerUpdates = ImmutableList.of(ReviewerStatusUpdate.create(updateTimestamp, changeOwner.getAccountId(), otherUserId, REVIEWER), ReviewerStatusUpdate.create(updateTimestamp, otherUserId, otherUserId, CC), ReviewerStatusUpdate.create(updateTimestamp, changeOwner.getAccountId(), otherUserId, REMOVED));
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getReviewerUpdates()).isEqualTo(expectedReviewerUpdates);
assertThat(notesAfterRewrite.getReviewerUpdates()).isEqualTo(expectedReviewerUpdates);
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
assertFixedCommits(commitsToFix, result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -9 +9 @@\n" + "-Reviewer: Other Account <2@gerrit>\n" + "+Reviewer: Gerrit User 2 <2@gerrit>\n", "@@ -11 +11 @@\n" + "-CC: Other Account <2@gerrit>\n" + "+CC: Gerrit User 2 <2@gerrit>\n", "@@ -9 +9 @@\n" + "-Removed: Other Account <2@gerrit>\n" + "+Removed: Gerrit User 2 <2@gerrit>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixCodeOwnersOnReviewChangeMessage.
@Test
public void fixCodeOwnersOnReviewChangeMessage() throws Exception {
Change c = newChange();
ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
ChangeUpdate invalidOnReviewUpdate = newUpdate(c, changeOwner);
invalidOnReviewUpdate.setChangeMessage("Patch Set 1: Any-Label+2 Other-Label+2 Code-Review+2\n\n" + "By voting Code-Review+2 the following files are now code-owner approved by Change Owner:\n" + " * file1.java\n" + " * file2.ts\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n" + "By voting Other-Label+2 the code-owners submit requirement is still overridden by Change Owner\n");
commitsToFix.add(invalidOnReviewUpdate.commit());
ChangeUpdate invalidOnReviewUpdateAnyOrder = newUpdate(c, changeOwner);
invalidOnReviewUpdateAnyOrder.setChangeMessage("Patch Set 1: Any-Label+2 Other-Label+2 Code-Review+2\n\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n" + "By voting Other-Label+2 the code-owners submit requirement is still overridden by Change Owner\n" + "By voting Code-Review+2 the following files are now code-owner approved by Change Owner:\n" + " * file1.java\n" + " * file2.ts\n");
commitsToFix.add(invalidOnReviewUpdateAnyOrder.commit());
ChangeUpdate invalidOnApprovalUpdate = newUpdate(c, otherUser);
invalidOnApprovalUpdate.setChangeMessage("Patch Set 1: -Code-Review\n\n" + "By removing the Code-Review+2 vote the following files are no longer explicitly code-owner approved by Other Account:\n" + " * file1.java\n" + " * file2.ts\n" + "\nThe listed files are still implicitly approved by Other Account.\n");
commitsToFix.add(invalidOnApprovalUpdate.commit());
ChangeUpdate invalidOnOverrideUpdate = newUpdate(c, changeOwner);
invalidOnOverrideUpdate.setChangeMessage("Patch Set 1: -Owners-Override\n\n" + "(1 comment)\n\n" + "By removing the Owners-Override+1 vote the code-owners submit requirement is no longer overridden by Change Owner\n");
commitsToFix.add(invalidOnOverrideUpdate.commit());
ChangeUpdate partiallyValidOnReviewUpdate = newUpdate(c, changeOwner);
partiallyValidOnReviewUpdate.setChangeMessage("Patch Set 1: Any-Label+2 Code-Review+2\n\n" + "By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file1.java\n" + " * file2.ts\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n");
commitsToFix.add(partiallyValidOnReviewUpdate.commit());
ChangeUpdate validOnApprovalUpdate = newUpdate(c, changeOwner);
validOnApprovalUpdate.setChangeMessage("Patch Set 1: Code-Review-2\n\n" + "By voting Code-Review-2 the following files are no longer explicitly code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file4.java\n");
validOnApprovalUpdate.commit();
ChangeUpdate validOnOverrideUpdate = newUpdate(c, changeOwner);
validOnOverrideUpdate.setChangeMessage("Patch Set 1: Owners-Override+1\n\n" + "By voting Owners-Override+1 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n");
validOnOverrideUpdate.commit();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.build().stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
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);
assertThat(changeMessages(notesBeforeRewrite)).hasSize(7);
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Patch Set 1: Any-Label+2 Other-Label+2 Code-Review+2\n\n" + "By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file1.java\n" + " * file2.ts\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n" + "By voting Other-Label+2 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n", "Patch Set 1: Any-Label+2 Other-Label+2 Code-Review+2\n\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n" + "By voting Other-Label+2 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n" + "By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file1.java\n" + " * file2.ts\n", "Patch Set 1: -Code-Review\n" + "\n" + "By removing the Code-Review+2 vote the following files are no longer explicitly code-owner approved by <GERRIT_ACCOUNT_2>:\n" + " * file1.java\n" + " * file2.ts\n" + "\nThe listed files are still implicitly approved by <GERRIT_ACCOUNT_2>.\n", "Patch Set 1: -Owners-Override\n" + "\n" + "(1 comment)\n" + "\n" + "By removing the Owners-Override+1 vote the code-owners submit requirement is no longer overridden by <GERRIT_ACCOUNT_1>\n", "Patch Set 1: Any-Label+2 Code-Review+2\n\n" + "By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file1.java\n" + " * file2.ts\n" + "By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n", "Patch Set 1: Code-Review-2\n\n" + "By voting Code-Review-2 the following files are no longer explicitly code-owner approved by <GERRIT_ACCOUNT_1>:\n" + " * file4.java\n", "Patch Set 1: Owners-Override+1\n" + "\n" + "By voting Owners-Override+1 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n");
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
assertFixedCommits(commitsToFix.build(), result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -8 +8 @@\n" + "-By voting Code-Review+2 the following files are now code-owner approved by Change Owner:\n" + "+By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n" + "@@ -11,2 +11,2 @@\n" + "-By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n" + "-By voting Other-Label+2 the code-owners submit requirement is still overridden by Change Owner\n" + "+By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n" + "+By voting Other-Label+2 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n", "@@ -8,3 +8,3 @@\n" + "-By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n" + "-By voting Other-Label+2 the code-owners submit requirement is still overridden by Change Owner\n" + "-By voting Code-Review+2 the following files are now code-owner approved by Change Owner:\n" + "+By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n" + "+By voting Other-Label+2 the code-owners submit requirement is still overridden by <GERRIT_ACCOUNT_1>\n" + "+By voting Code-Review+2 the following files are now code-owner approved by <GERRIT_ACCOUNT_1>:\n", "@@ -8 +8 @@\n" + "-By removing the Code-Review+2 vote the following files are no longer explicitly code-owner approved by Other Account:\n" + "+By removing the Code-Review+2 vote the following files are no longer explicitly code-owner approved by <GERRIT_ACCOUNT_2>:\n" + "@@ -12 +12 @@\n" + "-The listed files are still implicitly approved by Other Account.\n" + "+The listed files are still implicitly approved by <GERRIT_ACCOUNT_2>.\n", "@@ -10 +10 @@\n" + "-By removing the Owners-Override+1 vote the code-owners submit requirement is no longer overridden by Change Owner\n" + "+By removing the Owners-Override+1 vote the code-owners submit requirement is no longer overridden by <GERRIT_ACCOUNT_1>\n", "@@ -11 +11 @@\n" + "-By voting Any-Label+2 the code-owners submit requirement is overridden by Change Owner\n" + "+By voting Any-Label+2 the code-owners submit requirement is overridden by <GERRIT_ACCOUNT_1>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixRemoveVoteChangeMessageWithNoFooterLabel_matchDuplicateAccounts.
@Test
public void fixRemoveVoteChangeMessageWithNoFooterLabel_matchDuplicateAccounts() throws Exception {
Account duplicateCodeOwner = Account.builder(Account.id(4), TimeUtil.now()).setFullName(changeOwner.getName()).setPreferredEmail("other@test.com").build();
accountCache.put(duplicateCodeOwner);
Change c = newChange();
ChangeUpdate approvalUpdate = newUpdate(c, changeOwner);
approvalUpdate.putApproval(VERIFIED, (short) +2);
approvalUpdate.putApprovalFor(duplicateCodeOwner.id(), VERIFIED, (short) -1);
approvalUpdate.commit();
writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Verified+2 by Change Owner <other@test.com>"), getAuthorIdent(changeOwner.getAccount()));
writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Verified+2 by Change Owner <change@owner.com>"), getAuthorIdent(changeOwner.getAccount()));
writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Verified-1 by Change Owner <other@test.com>"), getAuthorIdent(changeOwner.getAccount()));
RunOptions options = new RunOptions();
options.dryRun = false;
BackfillResult result = rewriter.backfillProject(project, repo, options);
assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -6 +6 @@\n" + "-Removed Verified+2 by Change Owner <other@test.com>\n" + "+Removed Verified+2 by <GERRIT_ACCOUNT_4>\n", "@@ -6 +6 @@\n" + "-Removed Verified+2 by Change Owner <change@owner.com>\n" + "+Removed Verified+2 by <GERRIT_ACCOUNT_1>\n", "@@ -6 +6 @@\n" + "-Removed Verified-1 by Change Owner <other@test.com>\n" + "+Removed Verified-1 by <GERRIT_ACCOUNT_4>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixLabelFooterIdent.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixLabelFooterIdent() throws Exception {
Change c = newChange();
String approverIdentToFix = getAccountIdentToFix(otherUser.getAccount());
String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
ChangeUpdate approvalUpdateByOtherUser = newUpdate(c, otherUser);
approvalUpdateByOtherUser.putApproval(VERIFIED, (short) -1);
approvalUpdateByOtherUser.commit();
ImmutableList<ObjectId> commitsToFix = new ImmutableList.Builder<ObjectId>().add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, "Label: -Verified " + approverIdentToFix, "Label: Custom-Label-1=-1 " + approverIdentToFix, "Label: Verified=+1", "Label: Custom-Label-1=+1", "Label: Custom-Label-2=+2 " + approverIdentToFix, "Label: Custom-Label-3=0 " + approverIdentToFix), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, "Label: -Verified " + changeOwnerIdentToFix, "Label: Custom-Label-1=+1"), getAuthorIdent(otherUser.getAccount()))).build();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
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()));
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<PatchSetApproval> expectedApprovals = ImmutableList.of(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(VERIFIED))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create("Custom-Label-1"))).value(+1).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create(VERIFIED))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-1"))).value(+1).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-2"))).value(+2).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-3"))).value(0).granted(updateTimestamp).build());
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
assertThat(notesAfterRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
assertFixedCommits(commitsToFix, result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -7,2 +7,2 @@\n" + "-Label: -Verified Other Account <2@gerrit>\n" + "-Label: Custom-Label-1=-1 Other Account <2@gerrit>\n" + "+Label: -Verified Gerrit User 2 <2@gerrit>\n" + "+Label: Custom-Label-1=-1 Gerrit User 2 <2@gerrit>\n" + "@@ -11,2 +11,2 @@\n" + "-Label: Custom-Label-2=+2 Other Account <2@gerrit>\n" + "-Label: Custom-Label-3=0 Other Account <2@gerrit>\n" + "+Label: Custom-Label-2=+2 Gerrit User 2 <2@gerrit>\n" + "+Label: Custom-Label-3=0 Gerrit User 2 <2@gerrit>\n", "@@ -7 +7 @@\n" + "-Label: -Verified Change Owner <1@gerrit>\n" + "+Label: -Verified Gerrit User 1 <1@gerrit>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixReviewerMessage.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixReviewerMessage() throws Exception {
Change c = newChange();
ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
ChangeUpdate addReviewerUpdate = newUpdate(c, changeOwner);
addReviewerUpdate.putReviewer(otherUserId, REVIEWER);
addReviewerUpdate.commit();
commitsToFix.add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, String.format("Removed reviewer %s.", otherUser.getAccount().fullName()), "Removed: " + getValidIdentAsString(otherUser.getAccount())), getAuthorIdent(changeOwner.getAccount())));
ChangeUpdate addCcUpdate = newUpdate(c, changeOwner);
addCcUpdate.putReviewer(otherUserId, CC);
addCcUpdate.commit();
commitsToFix.add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, String.format("Removed cc %s with the following votes:\n\n * Code-Review+2", otherUser.getAccount().fullName()), "Removed: " + getValidIdentAsString(otherUser.getAccount())), getAuthorIdent(changeOwner.getAccount())));
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.build().stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
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()));
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<ReviewerStatusUpdate> expectedReviewerUpdates = ImmutableList.of(ReviewerStatusUpdate.create(addReviewerUpdate.when, changeOwner.getAccountId(), otherUserId, REVIEWER), ReviewerStatusUpdate.create(updateTimestamp, changeOwner.getAccountId(), otherUserId, REMOVED), ReviewerStatusUpdate.create(addCcUpdate.when, changeOwner.getAccountId(), otherUserId, CC), ReviewerStatusUpdate.create(updateTimestamp, changeOwner.getAccountId(), otherUserId, REMOVED));
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getReviewerUpdates()).isEqualTo(expectedReviewerUpdates);
assertThat(changeMessages(notesBeforeRewrite)).containsExactly("Removed reviewer Other Account.", "Removed cc Other Account with the following votes:\n\n * Code-Review+2");
assertThat(notesAfterRewrite.getReviewerUpdates()).isEqualTo(expectedReviewerUpdates);
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Removed reviewer", "Removed cc");
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
assertFixedCommits(commitsToFix.build(), result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -6 +6 @@\n" + "-Removed reviewer Other Account.\n" + "+Removed reviewer\n", "@@ -6,3 +6 @@\n" + "-Removed cc Other Account with the following votes:\n" + "-\n" + "- * Code-Review+2\n" + "+Removed cc\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Aggregations