use of com.google.gerrit.server.ReviewerStatusUpdate in project gerrit by GerritCodeReview.
the class ChangeJson method reviewerUpdates.
private Collection<ReviewerUpdateInfo> reviewerUpdates(ChangeData cd) {
List<ReviewerStatusUpdate> reviewerUpdates = cd.reviewerUpdates();
List<ReviewerUpdateInfo> result = new ArrayList<>(reviewerUpdates.size());
for (ReviewerStatusUpdate c : reviewerUpdates) {
ReviewerUpdateInfo change = new ReviewerUpdateInfo(c.date(), accountLoader.get(c.updatedBy()), accountLoader.get(c.reviewer()), c.state().asReviewerState());
result.add(change);
}
return result;
}
use of com.google.gerrit.server.ReviewerStatusUpdate 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.ReviewerStatusUpdate 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.ReviewerStatusUpdate in project gerrit by GerritCodeReview.
the class ChangeNotesParser method buildReviewerUpdates.
private List<ReviewerStatusUpdate> buildReviewerUpdates() {
List<ReviewerStatusUpdate> result = new ArrayList<>();
HashMap<Account.Id, ReviewerStateInternal> lastState = new HashMap<>();
for (ReviewerStatusUpdate u : Lists.reverse(reviewerUpdates)) {
if (!Objects.equals(ownerId, u.reviewer()) && lastState.get(u.reviewer()) != u.state()) {
result.add(u);
lastState.put(u.reviewer(), u.state());
}
}
return result;
}
Aggregations