use of com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixDeleteChangeMessageCommitMessage.
@Test
public void fixDeleteChangeMessageCommitMessage() throws Exception {
Change c = newChange();
ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
ChangeUpdate invalidDeleteChangeMessageUpdate = newUpdate(c, changeOwner);
invalidDeleteChangeMessageUpdate.setChangeMessage("Change message removed by: " + changeOwner.getName());
commitsToFix.add(invalidDeleteChangeMessageUpdate.commit());
ChangeUpdate invalidDeleteChangeMessageUpdateWithReason = newUpdate(c, changeOwner);
invalidDeleteChangeMessageUpdateWithReason.setChangeMessage(String.format("Change message removed by: %s\nReason: %s", changeOwner.getName(), "contains confidential information"));
commitsToFix.add(invalidDeleteChangeMessageUpdateWithReason.commit());
ChangeUpdate validDeleteChangeMessageUpdate = newUpdate(c, changeOwner);
validDeleteChangeMessageUpdate.setChangeMessage("Change message removed by: <GERRIT_ACCOUNT_1>");
validDeleteChangeMessageUpdate.commit();
ChangeUpdate validDeleteChangeMessageUpdateWithReason = newUpdate(c, changeOwner);
validDeleteChangeMessageUpdateWithReason.setChangeMessage("Change message removed by: <GERRIT_ACCOUNT_1>\nReason: abusive language");
validDeleteChangeMessageUpdateWithReason.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)).containsExactly("Change message removed by: Change Owner", "Change message removed by: Change Owner\n" + "Reason: contains confidential information", "Change message removed by: <GERRIT_ACCOUNT_1>", "Change message removed by: <GERRIT_ACCOUNT_1>\n" + "Reason: abusive language");
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Change message removed", "Change message removed\n" + "Reason: contains confidential information", "Change message removed by: <GERRIT_ACCOUNT_1>", "Change message removed by: <GERRIT_ACCOUNT_1>\n" + "Reason: abusive language");
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" + "-Change message removed by: Change Owner\n" + "+Change message removed\n", "@@ -6 +6 @@\n" + "-Change message removed by: Change Owner\n" + "+Change message removed\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixRemoveVoteChangeMessage.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixRemoveVoteChangeMessage() throws Exception {
Change c = newChange();
String approverIdentToFix = getAccountIdentToFix(otherUser.getAccount());
ChangeUpdate approvalUpdateByOtherUser = newUpdate(c, otherUser);
approvalUpdateByOtherUser.putApproval(CODE_REVIEW, (short) +2);
approvalUpdateByOtherUser.putApproval("Custom-Label", (short) -1);
approvalUpdateByOtherUser.putApprovalFor(changeOwner.getAccountId(), VERIFIED, (short) -1);
approvalUpdateByOtherUser.commit();
ImmutableList<ObjectId> commitsToFix = new ImmutableList.Builder<ObjectId>().add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Code-Review+2 by " + otherUser.getNameEmail(), "Label: -Code-Review " + approverIdentToFix), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Custom-Label-1 by " + otherUser.getNameEmail(), "Label: -Custom-Label " + getValidIdentAsString(otherUser.getAccount())), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Verified+2 by " + changeOwner.getNameEmail(), "Label: -Verified"), 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<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(), otherUserId, LabelId.create("Custom-Label"))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create(CODE_REVIEW))).value(0).granted(updateTimestamp).build());
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(changeMessages(notesBeforeRewrite)).containsExactly("Removed Code-Review+2 by Other Account <other@account.com>", "Removed Custom-Label-1 by Other Account <other@account.com>", "Removed Verified+2 by Change Owner <change@owner.com>");
assertThat(notesBeforeRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Removed Code-Review+2 by <GERRIT_ACCOUNT_2>", "Removed Custom-Label-1 by <GERRIT_ACCOUNT_2>", "Removed Verified+2 by <GERRIT_ACCOUNT_1>");
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("@@ -6 +6 @@\n" + "-Removed Code-Review+2 by Other Account <other@account.com>\n" + "+Removed Code-Review+2 by <GERRIT_ACCOUNT_2>\n" + "@@ -9 +9 @@\n" + "-Label: -Code-Review Other Account <2@gerrit>\n" + "+Label: -Code-Review Gerrit User 2 <2@gerrit>\n", "@@ -6 +6 @@\n" + "-Removed Custom-Label-1 by Other Account <other@account.com>\n" + "+Removed Custom-Label-1 by <GERRIT_ACCOUNT_2>\n", "@@ -6 +6 @@\n" + "-Removed Verified+2 by Change Owner <change@owner.com>\n" + "+Removed Verified+2 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.server.notedb.ReviewerStateInternal.REMOVED 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.server.notedb.ReviewerStateInternal.REMOVED 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();
}
use of com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixAttentionFooter.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixAttentionFooter() throws Exception {
Change c = newChange();
ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
// Only 'reason' fix is required
ChangeUpdate invalidAttentionSetUpdate = newUpdate(c, changeOwner);
invalidAttentionSetUpdate.putReviewer(otherUserId, REVIEWER);
invalidAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
commitsToFix.add(invalidAttentionSetUpdate.commit());
ChangeUpdate invalidMultipleAttentionSetUpdate = newUpdate(c, changeOwner);
invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())));
invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())));
commitsToFix.add(invalidMultipleAttentionSetUpdate.commit());
String otherUserIdentToFix = getAccountIdentToFix(otherUser.getAccount());
String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
commitsToFix.add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, // Only 'person_ident' fix is required
"Attention: " + gson.toJson(new AttentionStatusInNoteDb(otherUserIdentToFix, Operation.ADD, "Added by someone using the hovercard menu")), // Both 'reason' and 'person_ident' fix is required
"Attention: " + gson.toJson(new AttentionStatusInNoteDb(changeOwnerIdentToFix, Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())))), getAuthorIdent(changeOwner.getAccount())));
ChangeUpdate validAttentionSetUpdate = newUpdate(c, changeOwner);
validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, "Removed by someone"));
validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "Added by someone"));
validAttentionSetUpdate.commit();
ChangeUpdate invalidRemovedByClickUpdate = newUpdate(c, changeOwner);
invalidRemovedByClickUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())));
commitsToFix.add(invalidRemovedByClickUpdate.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()));
notesBeforeRewrite.getAttentionSetUpdates();
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<AttentionSetUpdate> attentionSetUpdatesBeforeRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
ImmutableList<AttentionSetUpdate> attentionSetUpdatesAfterRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, "Removed by someone by clicking the attention icon"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, "Someone replied on the change"), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Someone replied on the change"), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, "Added by someone using the hovercard menu"));
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesBeforeRewrite);
assertThat(notesAfterRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesAfterRewrite);
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).hasSize(4);
assertThat(commitHistoryDiff.get(0)).isEqualTo("@@ -8 +8 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by Other Account using the hovercard menu\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}\n");
assertThat(Arrays.asList(commitHistoryDiff.get(1).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Other Account replied on the change\"}", "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Someone replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone using the hovercard menu\"}");
assertThat(Arrays.asList(commitHistoryDiff.get(2).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Other Account \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "-Attention: {\"person_ident\":\"Change Owner \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Other Account replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Someone replied on the change\"}");
assertThat(commitHistoryDiff.get(3)).isEqualTo("@@ -7 +7 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account by clicking the attention icon\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone by clicking the attention icon\"}\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Aggregations