Search in sources :

Example 1 with AttentionSetInput

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);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Change(com.google.gerrit.entities.Change) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with AttentionSetInput

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()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with AttentionSetInput

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();
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with AttentionSetInput

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);
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with AttentionSetInput

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);
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Instant(java.time.Instant) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AttentionSetInput (com.google.gerrit.extensions.api.changes.AttentionSetInput)34 Test (org.junit.Test)34 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)32 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)31 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)21 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)7 TestAccount (com.google.gerrit.acceptance.TestAccount)5 Change (com.google.gerrit.entities.Change)3 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)3 AttentionSetInfo (com.google.gerrit.extensions.common.AttentionSetInfo)3 Account (com.google.gerrit.entities.Account)2 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)2 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)2 Result (com.google.gerrit.acceptance.PushOneCommit.Result)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 HashtagsInput (com.google.gerrit.extensions.api.changes.HashtagsInput)1 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)1 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1