use of com.google.gerrit.extensions.api.changes.AttentionSetInput 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.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method removeFromAttentionSetEmail_withTemplateReason.
@Test
public void removeFromAttentionSetEmail_withTemplateReason() throws Exception {
PushOneCommit.Result r = createChange();
// implicitly adds the user to the attention set when adding as reviewer
change(r).addReviewer(user.email());
sender.clear();
requestScopeOperations.setApiUser(user.id());
String templateReason = "Removed by " + AccountTemplateUtil.getAccountTemplate(user.id());
change(r).attention(user.id().toString()).remove(new AttentionSetInput(templateReason));
String emailBody = Iterables.getOnlyElement(sender.getMessages()).body();
assertThat(emailBody).contains(String.format("%s removed themselves from the attention set of this change.\n" + " The reason is: Removed by %s.", user.fullName(), user.getNameEmail()));
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method robotsNotAddedToAttentionSet.
@Test
public void robotsNotAddedToAttentionSet() throws Exception {
TestAccount robot = accountCreator.create("robot1", "robot1@example.com", "Ro Bot", "Ro", ServiceUserClassifier.SERVICE_USERS);
PushOneCommit.Result r = createChange();
// Make the robot active on the change.
change(r).addReviewer(robot.email());
// Throw an error when adding a robot explicitly.
BadRequestException exception = assertThrows(BadRequestException.class, () -> change(r).addToAttentionSet(new AttentionSetInput(robot.email(), "reason")));
assertThat(exception.getMessage()).isEqualTo("robot1@example.com is a robot, and robots can't be added to the attention set.");
// Robots are not added implicitly.
change(r).addReviewer(robot.email());
assertThat(r.getChange().attentionSet()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method accountsWithNoReadPermissionIgnoredOnReply.
@Test
public void accountsWithNoReadPermissionIgnoredOnReply() throws Exception {
// Create a group with user.
GroupInput groupInput = new GroupInput();
groupInput.name = name("User");
groupInput.members = ImmutableList.of(String.valueOf(user.id()));
GroupInfo group = gApi.groups().create(groupInput).get();
PushOneCommit.Result r = createChange();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
// remove read permission for user.
projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/*").group(AccountGroup.uuid(group.id))).update();
// removing user without permissions from attention set is allowed on reply.
gApi.changes().id(r.getChangeId()).current().review(new ReviewInput().removeUserFromAttentionSet(user.email(), "reason"));
// Add user to attention throws an exception.
assertThrows(AuthException.class, () -> change(r).addToAttentionSet(new AttentionSetInput(user.email(), "reason")));
// Add user to attention set is ignored on reply.
gApi.changes().id(r.getChangeId()).current().review(new ReviewInput().addUserToAttentionSet(user.email(), "reason"));
assertThat(Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, user)).operation()).isEqualTo(Operation.REMOVE);
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput 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);
}
Aggregations