diff --git a/java/com/google/gerrit/mail/MailHeader.java b/java/com/google/gerrit/mail/MailHeader.java index 2f31a9c47f..2700f81262 100644 --- a/java/com/google/gerrit/mail/MailHeader.java +++ b/java/com/google/gerrit/mail/MailHeader.java @@ -18,6 +18,7 @@ package com.google.gerrit.mail; public enum MailHeader { // Gerrit metadata holders ASSIGNEE("Gerrit-Assignee"), + ATTENTION("Gerrit-Attention"), BRANCH("Gerrit-Branch"), CC("Gerrit-CC"), COMMENT_IN_REPLY_TO("Comment-In-Reply-To"), diff --git a/java/com/google/gerrit/server/mail/send/ChangeEmail.java b/java/com/google/gerrit/server/mail/send/ChangeEmail.java index 1e984c1f68..122030071b 100644 --- a/java/com/google/gerrit/server/mail/send/ChangeEmail.java +++ b/java/com/google/gerrit/server/mail/send/ChangeEmail.java @@ -14,6 +14,9 @@ package com.google.gerrit.server.mail.send; +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.gerrit.server.util.AttentionSetUtil.additionsOnly; + import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -484,6 +487,9 @@ public abstract class ChangeEmail extends NotificationEmail { for (String reviewer : getEmailsByState(ReviewerStateInternal.CC)) { footers.add(MailHeader.CC.withDelimiter() + reviewer); } + for (String attentionSet : getAttentionSet()) { + footers.add(MailHeader.ATTENTION.withDelimiter() + attentionSet); + } } /** @@ -509,6 +515,19 @@ public abstract class ChangeEmail extends NotificationEmail { return reviewers; } + private Set getAttentionSet() { + Set attentionSet = new TreeSet<>(); + try { + attentionSet = + additionsOnly(changeData.attentionSet()).stream() + .map(a -> getNameEmailFor(a.account())) + .collect(toImmutableSet()); + } catch (StorageException e) { + logger.atWarning().withCause(e).log("Cannot get change attention set"); + } + return attentionSet; + } + public boolean getIncludeDiff() { return args.settings.includeDiff; } diff --git a/javatests/com/google/gerrit/acceptance/rest/change/AttentionSetIT.java b/javatests/com/google/gerrit/acceptance/rest/change/AttentionSetIT.java index ed4c33a9c6..cc6b199a89 100644 --- a/javatests/com/google/gerrit/acceptance/rest/change/AttentionSetIT.java +++ b/javatests/com/google/gerrit/acceptance/rest/change/AttentionSetIT.java @@ -1355,6 +1355,30 @@ public class AttentionSetIT extends AbstractDaemonTest { assertThat(attentionSet).hasReasonThat().isEqualTo("Reviewer was added"); } + @Test + public void attentionSetEmailFooter() throws Exception { + PushOneCommit.Result r = createChange(); + + // Add user to attention set. They receive an email with the attention footer. + change(r).addReviewer(user.id().toString()); + assertThat(Iterables.getOnlyElement(sender.getMessages()).body()) + .contains("Gerrit-Attention: " + user.fullName()); + sender.clear(); + + // Irrelevant reply, User is still in the attention set. + change(r).current().review(ReviewInput.approve()); + assertThat(Iterables.getOnlyElement(sender.getMessages()).body()) + .contains("Gerrit-Attention: " + user.fullName()); + sender.clear(); + + // Abandon the change which removes user from attention set; there is an email but without the + // attention footer. + change(r).abandon(); + assertThat(Iterables.getOnlyElement(sender.getMessages()).body()) + .doesNotContain("Gerrit-Attention: " + user.fullName()); + sender.clear(); + } + private List getAttentionSetUpdatesForUser( PushOneCommit.Result r, TestAccount account) { return getAttentionSetUpdates(r.getChange().getId()).stream() diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts index e80e646c46..ea26a514fd 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts @@ -493,6 +493,15 @@ export const htmlTemplate = html` + + Changes requesting my attention + + + "Gerrit-Attention: Your Name + <your.email@example.com>" + + + Changes from a specific owner