use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeNotesTest method filterLatestAttentionStatus.
@Test
public void filterLatestAttentionStatus() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
AttentionSetUpdate attentionSetUpdate = AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "test");
update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate));
update.commit();
update = newUpdate(c, changeOwner);
attentionSetUpdate = AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.REMOVE, "test");
update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate));
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getAttentionSet()).containsExactly(addTimestamp(attentionSetUpdate, c));
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeNotesTest method addAttentionStatus_rejectTimestamp.
@Test
public void addAttentionStatus_rejectTimestamp() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
AttentionSetUpdate attentionSetUpdate = AttentionSetUpdate.createFromRead(Instant.now(), changeOwner.getAccountId(), Operation.ADD, "test");
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate)));
assertThat(thrown).hasMessageThat().contains("must not specify timestamp for write");
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeNotesTest method addAllAttentionUpdates.
@Test
public void addAllAttentionUpdates() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
AttentionSetUpdate attentionSetUpdate = AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "test");
update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate));
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getAttentionSetUpdates()).containsExactly(addTimestamp(attentionSetUpdate, c));
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeNotesTest method addAttentionStatus.
@Test
public void addAttentionStatus() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
AttentionSetUpdate attentionSetUpdate = AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "test");
update.addToPlannedAttentionSetUpdates(ImmutableSet.of(attentionSetUpdate));
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getAttentionSet()).containsExactly(addTimestamp(attentionSetUpdate, c));
}
use of com.google.gerrit.entities.AttentionSetUpdate in project gerrit by GerritCodeReview.
the class ChangeUpdate method updateAttentionSet.
/**
* Any updates to the attention set must be done in {@link #addToPlannedAttentionSetUpdates}. This
* method is called after all the updates are finished to do the updates once and for real.
*
* <p>Changing the behaviour of this method might affect the way a ChangeUpdate is considered to
* be an "Attention Set Change Only". Make sure the {@link #isAttentionSetChangeOnly} logic is
* amended as well if needed.
*/
private void updateAttentionSet(StringBuilder msg) {
if (plannedAttentionSetUpdates == null) {
plannedAttentionSetUpdates = new HashMap<>();
}
Set<Account.Id> currentUsersInAttentionSet = AttentionSetUtil.additionsOnly(getNotes().getAttentionSet()).stream().map(AttentionSetUpdate::account).collect(Collectors.toSet());
// Current reviewers/ccs are the reviewers/ccs before the update + the new reviewers/ccs - the
// deleted reviewers/ccs.
Set<Account.Id> currentReviewers = Stream.concat(getNotes().getReviewers().all().stream(), reviewers.entrySet().stream().filter(r -> r.getValue().asReviewerState() != ReviewerState.REMOVED).map(r -> r.getKey())).collect(Collectors.toSet());
currentReviewers.removeAll(reviewers.entrySet().stream().filter(r -> r.getValue().asReviewerState() == ReviewerState.REMOVED).map(r -> r.getKey()).collect(ImmutableSet.toImmutableSet()));
removeInactiveUsersFromAttentionSet(currentReviewers);
for (AttentionSetUpdate attentionSetUpdate : plannedAttentionSetUpdates.values()) {
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && currentUsersInAttentionSet.contains(attentionSetUpdate.account())) {
// Skip users that are already in the attention set: no need to re-add them.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.REMOVE && !currentUsersInAttentionSet.contains(attentionSetUpdate.account())) {
// Skip users that are not in the attention set: no need to remove them.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && serviceUserClassifier.isServiceUser(attentionSetUpdate.account())) {
// Skip adding robots to the attention set.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && approvals.rowKeySet().contains(LabelId.legacySubmit().get())) {
// This ensures we don't add users to the attention set on submit.
continue;
}
// Don't add accounts that are not active in the change to the attention set.
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && !isActiveOnChange(currentReviewers, attentionSetUpdate.account())) {
continue;
}
addFooter(msg, FOOTER_ATTENTION, noteUtil.attentionSetUpdateToJson(attentionSetUpdate));
}
}
Aggregations