Search in sources :

Example 6 with AttentionSetUpdate

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();
}
Also used : Ref(org.eclipse.jgit.lib.Ref) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Change(com.google.gerrit.entities.Change) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Test(org.junit.Test)

Example 7 with AttentionSetUpdate

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));
}
Also used : AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate)

Example 8 with 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);
}
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 9 with AttentionSetUpdate

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);
}
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)

Example 10 with AttentionSetUpdate

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

Aggregations

AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)65 Test (org.junit.Test)61 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)52 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)51 AttentionSetInput (com.google.gerrit.extensions.api.changes.AttentionSetInput)21 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)21 Change (com.google.gerrit.entities.Change)12 TestAccount (com.google.gerrit.acceptance.TestAccount)9 Account (com.google.gerrit.entities.Account)4 ImmutableList (com.google.common.collect.ImmutableList)3 Operation (com.google.gerrit.entities.AttentionSetUpdate.Operation)3 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)3 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)3 AttentionSetInfo (com.google.gerrit.extensions.common.AttentionSetInfo)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Result (com.google.gerrit.acceptance.PushOneCommit.Result)2 LabelId (com.google.gerrit.entities.LabelId)2 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)2 SubmitRecord (com.google.gerrit.entities.SubmitRecord)2 Inject (com.google.inject.Inject)2