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;
}
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");
}
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");
}
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()));
}
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");
}
Aggregations