use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method removeUser.
@Test
public void removeUser() throws Exception {
PushOneCommit.Result r = createChange();
// implictly adds the user to the attention set when adding as reviewer
change(r).addReviewer(user.email());
sender.clear();
requestScopeOperations.setApiUser(user.id());
fakeClock.advance(Duration.ofSeconds(42));
change(r).attention(user.id().toString()).remove(new AttentionSetInput("removed"));
AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), user.id(), AttentionSetUpdate.Operation.REMOVE, "removed");
assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
// The removal also shows up in AttentionSetInfo.
AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().removedFromAttentionSet.values());
assertThat(attentionSetInfo.reason).isEqualTo("removed");
assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(user.id()));
// Second removal is ignored.
fakeClock.advance(Duration.ofSeconds(42));
change(r).attention(user.id().toString()).remove(new AttentionSetInput("removed again"));
assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
// Only one email since the second remove was ignored.
String emailBody = Iterables.getOnlyElement(sender.getMessages()).body();
assertThat(emailBody).contains(user.fullName() + " removed themselves from the attention set of this change.\n" + " The reason is: removed.");
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method removedCcRemovedFromAttentionSet.
@Test
public void removedCcRemovedFromAttentionSet() throws Exception {
PushOneCommit.Result r = createChange();
// Add cc
ReviewerInput input = new ReviewerInput();
input.reviewer = user.email();
input.state = ReviewerState.CC;
change(r).addReviewer(input);
// Add them to the attention set
AttentionSetInput attentionSetInput = new AttentionSetInput();
attentionSetInput.user = user.email();
attentionSetInput.reason = "reason";
change(r).addToAttentionSet(attentionSetInput);
// Remove them from cc
change(r).reviewer(user.email()).remove();
AttentionSetUpdate attentionSet = Iterables.getOnlyElement(r.getChange().attentionSet());
assertThat(attentionSet).hasAccountIdThat().isEqualTo(user.id());
assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.REMOVE);
assertThat(attentionSet).hasReasonThat().isEqualTo("Reviewer/Cc was removed");
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AttentionSetIT method cannotRemoveIrrelevantUserToAttentionSetWithUserInInput.
@Test
public void cannotRemoveIrrelevantUserToAttentionSetWithUserInInput() throws Exception {
PushOneCommit.Result r = createChange();
BadRequestException exception = assertThrows(BadRequestException.class, () -> change(r).attention(user.email()).remove(new AttentionSetInput(user.email(), "reason")));
assertThat(exception.getMessage()).isEqualTo(String.format("%s doesn't exist or is not active on the change as an owner, uploader, reviewer, " + "or cc so they can't be added to the attention set", user.email()));
}
use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method attentionSetIndexed.
@Test
public void attentionSetIndexed() throws Exception {
assume().that(getSchema().hasField(ChangeField.ATTENTION_SET_USERS)).isTrue();
assume().that(getSchema().hasField(ChangeField.ATTENTION_SET_USERS_COUNT)).isTrue();
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChange(repo));
AttentionSetInput input = new AttentionSetInput(userId.toString(), "some reason");
gApi.changes().id(change1.getChangeId()).addToAttentionSet(input);
assertQuery("is:attention", change1);
assertQuery("-is:attention", change2);
assertQuery("has:attention", change1);
assertQuery("-has:attention", change2);
assertQuery("attention:" + user.getUserName().get(), change1);
assertQuery("-attention:" + userId.toString(), change2);
gApi.changes().id(change1.getChangeId()).attention(userId.toString()).remove(new AttentionSetInput("removed again"));
assertQuery("-is:attention", change1, change2);
}
Aggregations