Search in sources :

Example 1 with AttentionSetUpdate

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

Example 2 with AttentionSetUpdate

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

Example 3 with AttentionSetUpdate

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

Example 4 with AttentionSetUpdate

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

Example 5 with AttentionSetUpdate

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));
    }
}
Also used : RefNames.changeMetaRef(com.google.gerrit.entities.RefNames.changeMetaRef) Comparator.naturalOrder(java.util.Comparator.naturalOrder) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) FOOTER_SUBMITTED_WITH(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMITTED_WITH) OBJ_BLOB(org.eclipse.jgit.lib.Constants.OBJ_BLOB) ProjectCache(com.google.gerrit.server.project.ProjectCache) FOOTER_HASHTAGS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_HASHTAGS) Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) SubmissionId(com.google.gerrit.entities.SubmissionId) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Assisted(com.google.inject.assistedinject.Assisted) FooterKey(org.eclipse.jgit.revwalk.FooterKey) RevWalk(org.eclipse.jgit.revwalk.RevWalk) FOOTER_ASSIGNEE(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_ASSIGNEE) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) FOOTER_PATCH_SET_DESCRIPTION(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET_DESCRIPTION) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) AssistedInject(com.google.inject.assistedinject.AssistedInject) NoteDbUtil.sanitizeFooter(com.google.gerrit.server.notedb.NoteDbUtil.sanitizeFooter) NoteMap(org.eclipse.jgit.notes.NoteMap) FOOTER_ATTENTION(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_ATTENTION) FOOTER_WORK_IN_PROGRESS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_WORK_IN_PROGRESS) ImmutableSet(com.google.common.collect.ImmutableSet) FOOTER_SUBJECT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBJECT) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) Set(java.util.Set) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) FOOTER_STATUS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_STATUS) Stream(java.util.stream.Stream) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FOOTER_LABEL(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_LABEL) Cell(com.google.common.collect.Table.Cell) FOOTER_SUBMISSION_ID(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMISSION_ID) Joiner(com.google.common.base.Joiner) AttentionSetUtil(com.google.gerrit.server.util.AttentionSetUtil) FOOTER_COMMIT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_COMMIT) FOOTER_CHANGE_ID(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_CHANGE_ID) FOOTER_REVERT_OF(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_REVERT_OF) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FOOTER_TAG(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TAG) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) FOOTER_REAL_USER(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_REAL_USER) ImmutableList(com.google.common.collect.ImmutableList) PatchSetApprovalUuidGenerator(com.google.gerrit.server.approval.PatchSetApprovalUuidGenerator) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) RobotComment(com.google.gerrit.entities.RobotComment) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Address(com.google.gerrit.entities.Address) FOOTER_BRANCH(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_BRANCH) FOOTER_PATCH_SET(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) FOOTER_GROUPS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_GROUPS) FOOTER_COPIED_LABEL(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_COPIED_LABEL) FOOTER_PRIVATE(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PRIVATE) FOOTER_TOPIC(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) CurrentUser(com.google.gerrit.server.CurrentUser) ValidationException(com.google.gerrit.server.validators.ValidationException) StorageException(com.google.gerrit.exceptions.StorageException) FOOTER_CURRENT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_CURRENT) IOException(java.io.IOException) TreeBasedTable(com.google.common.collect.TreeBasedTable) ObjectId(org.eclipse.jgit.lib.ObjectId) FOOTER_CHERRY_PICK_OF(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_CHERRY_PICK_OF) Project(com.google.gerrit.entities.Project) LabelVote(com.google.gerrit.server.util.LabelVote) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Table(com.google.common.collect.Table) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId)

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