Search in sources :

Example 1 with FOOTER_ATTENTION

use of com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_ATTENTION 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

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Table (com.google.common.collect.Table)1 Cell (com.google.common.collect.Table.Cell)1 TreeBasedTable (com.google.common.collect.TreeBasedTable)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)1 Operation (com.google.gerrit.entities.AttentionSetUpdate.Operation)1 Change (com.google.gerrit.entities.Change)1 Comment (com.google.gerrit.entities.Comment)1 HumanComment (com.google.gerrit.entities.HumanComment)1 LabelId (com.google.gerrit.entities.LabelId)1