Link patchset-level robot comments to findings tab

Currently, we link all patchset-level comments to the comments tab,
but it doesn't make sense for robot comments since we don't show them
in the comments tab. Thus, patchset-level robot comments will be linked
to the findings tab.

There is an exception: Comments are grouped by file, and thus both human
and robot comments can be in the same group and have the same link.
For this case, links to the files of such potential groups were omitted.

Change-Id: Iaf795bc34483689497e7cf8b747faf2f68a244a3
diff --git a/java/com/google/gerrit/server/config/UrlFormatter.java b/java/com/google/gerrit/server/config/UrlFormatter.java
index 8fc0d9e..d3f90e5 100644
--- a/java/com/google/gerrit/server/config/UrlFormatter.java
+++ b/java/com/google/gerrit/server/config/UrlFormatter.java
@@ -52,6 +52,11 @@
     return getChangeViewUrl(change.getProject(), change.getId()).map(url -> url + "?tab=comments");
   }
 
+  /** Returns the URL for viewing the findings tab view of a change. */
+  default Optional<String> getFindingsTabView(Change change) {
+    return getChangeViewUrl(change.getProject(), change.getId()).map(url -> url + "?tab=findings");
+  }
+
   /** Returns the URL for viewing a file in a given patch set of a change. */
   default Optional<String> getPatchFileView(Change change, int patchsetId, String filename) {
     return getChangeViewUrl(change.getProject(), change.getId())
diff --git a/java/com/google/gerrit/server/mail/send/CommentSender.java b/java/com/google/gerrit/server/mail/send/CommentSender.java
index deaa926..f3cccf2 100644
--- a/java/com/google/gerrit/server/mail/send/CommentSender.java
+++ b/java/com/google/gerrit/server/mail/send/CommentSender.java
@@ -93,6 +93,11 @@
       return args.urlFormatter.get().getCommentsTabView(change).orElse(null);
     }
 
+    /** @return a web link to the findings tab view of a change. */
+    public String getFindingsTabLink() {
+      return args.urlFormatter.get().getFindingsTabView(change).orElse(null);
+    }
+
     /**
      * @return A title for the group, i.e. "Commit Message", "Merge List", or "File [[filename]]".
      */
@@ -386,9 +391,7 @@
 
     for (CommentSender.FileCommentGroup group : getGroupedInlineComments(repo)) {
       Map<String, Object> groupData = new HashMap<>();
-      if (group.filename.equals(Patch.PATCHSET_LEVEL)) {
-        groupData.put("link", group.getCommentsTabLink());
-      } else {
+      if (!group.filename.equals(Patch.PATCHSET_LEVEL)) {
         groupData.put("link", group.getFileLink());
       }
       groupData.put("title", group.getTitle());
@@ -420,7 +423,11 @@
         // Set the comment link.
 
         if (comment.key.filename.equals(Patch.PATCHSET_LEVEL)) {
-          commentData.put("link", group.getCommentsTabLink());
+          if (comment instanceof RobotComment) {
+            commentData.put("link", group.getFindingsTabLink());
+          } else {
+            commentData.put("link", group.getCommentsTabLink());
+          }
         } else if (comment.lineNbr == 0) {
           commentData.put("link", group.getFileLink());
         } else {