From d8c493109a810bba2d8d4c5d048087a4671f875b Mon Sep 17 00:00:00 2001 From: Wyatt Allen Date: Tue, 3 Oct 2017 10:08:15 +0100 Subject: [PATCH] Add Gerrit-Comment-In-Reply-To footer Change-Id: I7860838077cb303331a50ac2855441534bb26d10 --- Documentation/user-notify.txt | 11 +++++++ .../server/mail/send/CommentSender.java | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/Documentation/user-notify.txt b/Documentation/user-notify.txt index 4b928f3509..3c922ed716 100644 --- a/Documentation/user-notify.txt +++ b/Documentation/user-notify.txt @@ -244,6 +244,17 @@ In comment emails, the has-labels footer states whether label votes had been posted in that notification using "Yes" or "No", for example `Gerrit-HasLabels: No`. +[[Gerrit-Comment-In-Reply-To]]Gerrit-Comment-In-Reply-To:: + +In comment emails, a comment-in-reply-to footer is present for each +account who has a comment that is replied-to in that set of comments. +For example, to apply a filter to Gerrit messages in which your own diff +comments are responded to, you might search for the following: + +---- + Gerrit-Comment-In-Reply-To: User Name +---- + GERRIT ------ Part of link:index.html[Gerrit Code Review] diff --git a/java/com/google/gerrit/server/mail/send/CommentSender.java b/java/com/google/gerrit/server/mail/send/CommentSender.java index 805527300f..fae42746f0 100644 --- a/java/com/google/gerrit/server/mail/send/CommentSender.java +++ b/java/com/google/gerrit/server/mail/send/CommentSender.java @@ -22,6 +22,7 @@ import com.google.gerrit.common.data.FilenameComparator; import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.extensions.api.changes.NotifyHandling; +import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Comment; import com.google.gerrit.reviewdb.client.Patch; @@ -243,6 +244,34 @@ public class CommentSender extends ReplyToChangeSender { return groups; } + /** Get the set of accounts whose comments have been replied to in this email. */ + private HashSet getReplyAccounts() { + HashSet replyAccounts = new HashSet<>(); + + // Track visited parent UUIDs to avoid cycles. + HashSet visitedUuids = new HashSet<>(); + + for (Comment comment : inlineComments) { + visitedUuids.add(comment.key.uuid); + + // Traverse the parent relation to the top of the comment thread. + Comment current = comment; + while (current.parentUuid != null && !visitedUuids.contains(current.parentUuid)) { + Optional optParent = getParent(current); + if (!optParent.isPresent()) { + // There is a parent UUID, but it cannot be loaded, break from the comment thread. + break; + } + + Comment parent = optParent.get(); + replyAccounts.add(parent.author.getId()); + visitedUuids.add(current.parentUuid); + current = parent; + } + } + return replyAccounts; + } + private String getCommentLinePrefix(Comment comment) { int lineNbr = comment.range == null ? comment.lineNbr : comment.range.startLine; StringBuilder sb = new StringBuilder(); @@ -497,6 +526,10 @@ public class CommentSender extends ReplyToChangeSender { footers.add("Gerrit-Comment-Date: " + getCommentTimestamp()); footers.add("Gerrit-HasComments: " + (hasComments ? "Yes" : "No")); footers.add("Gerrit-HasLabels: " + (labels.isEmpty() ? "No" : "Yes")); + + for (Account.Id account : getReplyAccounts()) { + footers.add("Gerrit-Comment-In-Reply-To: " + getNameEmailFor(account)); + } } private String getLine(PatchFile fileInfo, short side, int lineNbr) {