Search in sources :

Example 31 with AttentionSetUpdate

use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.

the class RemoveFromAttentionSetOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException {
    ChangeData changeData = changeDataFactory.create(ctx.getNotes());
    Optional<AttentionSetUpdate> existingEntry = changeData.attentionSet().stream().filter(u -> u.account().equals(attentionUserId)).findAny();
    if (!existingEntry.isPresent() || existingEntry.get().operation() == Operation.REMOVE) {
        // We still need to perform this update to ensure that we don't add the user in a follow-up
        // operation, but no need to send an email about it.
        notify = false;
    }
    change = ctx.getChange();
    ChangeUpdate update = ctx.getUpdate(ctx.getChange().currentPatchSetId());
    update.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(attentionUserId, Operation.REMOVE, reason));
    return true;
}
Also used : Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) Inject(com.google.inject.Inject) Account(com.google.gerrit.entities.Account) IOException(java.io.IOException) Assisted(com.google.inject.assistedinject.Assisted) MessageIdGenerator(com.google.gerrit.server.mail.send.MessageIdGenerator) RemoveFromAttentionSetSender(com.google.gerrit.server.mail.send.RemoveFromAttentionSetSender) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) AttentionSetEmail(com.google.gerrit.server.util.AttentionSetEmail) Objects.requireNonNull(java.util.Objects.requireNonNull) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Optional(java.util.Optional) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) ChangeContext(com.google.gerrit.server.update.ChangeContext) FluentLogger(com.google.common.flogger.FluentLogger) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 32 with AttentionSetUpdate

use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushWithReviewerAddsToAttentionSet.

@Test
public void pushWithReviewerAddsToAttentionSet() throws Exception {
    String pushSpec = "refs/for/master%r=" + user.email();
    PushOneCommit.Result r = pushTo(pushSpec);
    r.assertOkStatus();
    AttentionSetUpdate attentionSet = Iterables.getOnlyElement(r.getChange().attentionSet());
    AttentionSetUpdateSubject.assertThat(attentionSet).hasAccountIdThat().isEqualTo(user.id());
    AttentionSetUpdateSubject.assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.ADD);
    AttentionSetUpdateSubject.assertThat(attentionSet).hasReasonThat().isEqualTo("Reviewer was added");
}
Also used : AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 33 with AttentionSetUpdate

use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.

the class AbstractSubmit method submitThatAddsUsersAsReviewersEnsuresTheyAreNotAddedToAttentionSet.

@Test
public void submitThatAddsUsersAsReviewersEnsuresTheyAreNotAddedToAttentionSet() throws Exception {
    PushOneCommit.Result r = createChange("refs/heads/master", "file1", "content");
    // Someone else approves, because if admin reviews, they will be added to the reviewers (and the
    // bug won't be reproduced).
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    change(r).current().review(ReviewInput.approve().addUserToAttentionSet(user.email(), "reason"));
    requestScopeOperations.setApiUser(admin.id());
    change(r).attention(admin.email()).remove(new AttentionSetInput("remove"));
    change(r).current().submit();
    AttentionSetUpdate attentionSet = Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, admin));
    assertThat(attentionSet.account()).isEqualTo(admin.id());
    assertThat(attentionSet.operation()).isEqualTo(AttentionSetUpdate.Operation.REMOVE);
    assertThat(attentionSet.reason()).isEqualTo("remove");
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 34 with AttentionSetUpdate

use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.

the class AttentionSetIT method addUser.

@Test
public void addUser() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    int accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), "first"))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), admin.id(), AttentionSetUpdate.Operation.ADD, "first");
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    // Second add is ignored.
    accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), "second"))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    // Only one email since the second add was ignored.
    String emailBody = Iterables.getOnlyElement(sender.getMessages()).body();
    assertThat(emailBody).contains(String.format("%s requires the attention of %s to this change.\n The reason is: first.", user.fullName(), admin.fullName()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with AttentionSetUpdate

use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.

the class AttentionSetIT method attentionSetStillChangesWithIgnoreAutomaticAttentionSetRulesWithInputList.

@Test
public void attentionSetStillChangesWithIgnoreAutomaticAttentionSetRulesWithInputList() throws Exception {
    PushOneCommit.Result r = createChange();
    change(r).addToAttentionSet(new AttentionSetInput(admin.email(), "reason"));
    change(r).current().review(ReviewInput.create().removeUserFromAttentionSet(admin.email(), "removed").blockAutomaticAttentionSetRules());
    // Admin is still removed although we block default attention set rules, since we remove
    // the admin manually.
    AttentionSetUpdate attentionSet = Iterables.getOnlyElement(r.getChange().attentionSet());
    assertThat(attentionSet).hasAccountIdThat().isEqualTo(admin.id());
    assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.REMOVE);
    assertThat(attentionSet).hasReasonThat().isEqualTo("removed");
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) 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