use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixAttentionFooter_okReason_noRewrite.
@Test
public void fixAttentionFooter_okReason_noRewrite() throws Exception {
Change c = newChange();
ImmutableList<String> okAccountNames = ImmutableList.of("Someone", "Someone else", "someone", "someone else", "Anonymous", "anonymous", "<GERRIT_ACCOUNT_1>", "<GERRIT_ACCOUNT_2>");
ImmutableList.Builder<AttentionSetUpdate> attentionSetUpdatesBeforeRewrite = new ImmutableList.Builder<>();
for (String okAccountName : okAccountNames) {
ChangeUpdate firstAttentionSetUpdate = newUpdate(c, changeOwner);
firstAttentionSetUpdate.putReviewer(otherUserId, REVIEWER);
firstAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", okAccountName)));
firstAttentionSetUpdate.commit();
ChangeUpdate secondAttentionSetUpdate = newUpdate(c, changeOwner);
secondAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", okAccountName)));
secondAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", okAccountName)));
secondAttentionSetUpdate.commit();
ChangeUpdate thirdAttentionSetUpdate = newUpdate(c, changeOwner);
thirdAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", okAccountName)));
thirdAttentionSetUpdate.commit();
attentionSetUpdatesBeforeRewrite.add(AttentionSetUpdate.createFromRead(thirdAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", okAccountName)), AttentionSetUpdate.createFromRead(secondAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", okAccountName)), AttentionSetUpdate.createFromRead(secondAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", okAccountName)), AttentionSetUpdate.createFromRead(firstAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", okAccountName)));
}
ChangeNotes notesBeforeRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesBeforeRewrite.build());
Ref metaRefBefore = repo.exactRef(RefNames.changeMetaRef(c.getId()));
RunOptions options = new RunOptions();
options.dryRun = false;
BackfillResult backfillResult = rewriter.backfillProject(project, repo, options);
ChangeNotes notesAfterRewrite = newNotes(c);
Ref metaRefAfter = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(notesBeforeRewrite.getMetaId()).isEqualTo(notesAfterRewrite.getMetaId());
assertThat(metaRefBefore.getObjectId()).isEqualTo(metaRefAfter.getObjectId());
assertThat(backfillResult.fixedRefDiff).isEmpty();
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeUpdateTest method addToAttentionSet.
private void addToAttentionSet(ChangeUpdate update) {
AttentionSetUpdate attentionSetUpdate = AttentionSetUpdate.createForWrite(otherUser.getAccountId(), AttentionSetUpdate.Operation.ADD, "test");
update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate));
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class AttentionSetIT method reviewAddsAllUsersInCommentThreadEvenOfDifferentChildBranch.
@Test
public void reviewAddsAllUsersInCommentThreadEvenOfDifferentChildBranch() throws Exception {
Account.Id changeOwner = accountOperations.newAccount().create();
Change.Id changeId = changeOperations.newChange().owner(changeOwner).create();
Account.Id user1 = accountOperations.newAccount().create();
Account.Id user2 = accountOperations.newAccount().create();
Account.Id user3 = accountOperations.newAccount().create();
Account.Id user4 = accountOperations.newAccount().create();
// Add users as reviewers.
gApi.changes().id(changeId.get()).addReviewer(user1.toString());
gApi.changes().id(changeId.get()).addReviewer(user2.toString());
gApi.changes().id(changeId.get()).addReviewer(user3.toString());
gApi.changes().id(changeId.get()).addReviewer(user4.toString());
// Add a comment thread with branches. Such threads occur if people reply in parallel without
// having seen/loaded the reply of another person.
String root = changeOperations.change(changeId).currentPatchset().newComment().author(user1).create();
String sibling1 = changeOperations.change(changeId).currentPatchset().newComment().author(user2).parentUuid(root).create();
String sibling2 = changeOperations.change(changeId).currentPatchset().newComment().author(user3).parentUuid(root).create();
changeOperations.change(changeId).currentPatchset().newComment().author(user4).parentUuid(sibling2).create();
// Clear the attention set. Necessary as we used Gerrit APIs above which affect the attention
// set.
AttentionSetInput clearAttention = new AttentionSetInput("clear attention set");
gApi.changes().id(changeId.get()).attention(user1.toString()).remove(clearAttention);
gApi.changes().id(changeId.get()).attention(user2.toString()).remove(clearAttention);
gApi.changes().id(changeId.get()).attention(user3.toString()).remove(clearAttention);
gApi.changes().id(changeId.get()).attention(user4.toString()).remove(clearAttention);
requestScopeOperations.setApiUser(changeOwner);
// Simulate that this reply is a child of sibling1 and thus parallel to sibling2 and its child.
gApi.changes().id(changeId.get()).current().review(reviewInReplyToComment(sibling1));
List<AttentionSetUpdate> attentionSetUpdates = getAttentionSetUpdates(changeId);
assertThat(attentionSetUpdates).comparingElementsUsing(hasAccount()).containsExactly(user1, user2, user3, user4);
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class AttentionSetIT method addMultipleUsers.
@Test
public void addMultipleUsers() throws Exception {
PushOneCommit.Result r = createChange();
Instant timestamp1 = fakeClock.now();
// implictly adds the user to the attention set when adding as reviewer
change(r).addReviewer(user.email());
fakeClock.advance(Duration.ofSeconds(42));
Instant timestamp2 = fakeClock.now();
int accountId2 = change(r).addToAttentionSet(new AttentionSetInput(admin.id().toString(), "manual update"))._accountId;
assertThat(accountId2).isEqualTo(admin.id().get());
AttentionSetUpdate expectedAttentionSetUpdate1 = AttentionSetUpdate.createFromRead(timestamp1, user.id(), AttentionSetUpdate.Operation.ADD, "Reviewer was added");
AttentionSetUpdate expectedAttentionSetUpdate2 = AttentionSetUpdate.createFromRead(timestamp2, admin.id(), AttentionSetUpdate.Operation.ADD, "manual update");
assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate1, expectedAttentionSetUpdate2);
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class AttentionSetIT method robotCanChangeAttentionSetExplicitly.
@Test
public void robotCanChangeAttentionSetExplicitly() throws Exception {
TestAccount robot = accountCreator.create("robot2", "robot2@example.com", "Ro Bot", "Ro", ServiceUserClassifier.SERVICE_USERS);
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(robot.id());
change(r).current().review(new ReviewInput().addUserToAttentionSet(admin.email(), "reason"));
AttentionSetUpdate attentionSet = Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, admin));
assertThat(attentionSet).hasAccountIdThat().isEqualTo(admin.id());
assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.ADD);
assertThat(attentionSet).hasReasonThat().isEqualTo("reason");
}
Aggregations