Harmonize extracting issue ids from matched pattern

ItsValitadeComment only considered the first group as issue id, while
the code that got moved from GerritHookFilter to IssueExtractor
considered each group as issue id.
We now uniformly only treat the first group as issue id.

Change-Id: Ib3d9a75bab8842a25f13113d21bc361aae71d8f8
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/util/IssueExtractor.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/util/IssueExtractor.java
index 480a70a..61c7ebe 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/util/IssueExtractor.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/util/IssueExtractor.java
@@ -42,10 +42,9 @@
       Matcher matcher = pattern.matcher(haystack);
 
       while (matcher.find()) {
-        int groupCount = matcher.groupCount();
-        for (int i = 1; i <= groupCount; i++) {
-          String group = matcher.group(i);
-          issues.add(group);
+        String issueId = extractMatchedWorkItems(matcher);
+        if (issueId != null) {
+          issues.add(issueId);
         }
       }
     }
@@ -53,6 +52,14 @@
     return issues.toArray(new String[issues.size()]);
   }
 
+  public String extractMatchedWorkItems(Matcher matcher) {
+    int groupCount = matcher.groupCount();
+    if (groupCount >= 1)
+      return matcher.group(1);
+    else
+      return null;
+  }
+
   /**
    * Gets the regular expression used to identify issue ids.
    * @return the regular expression, or {@code null}, if there is no pattern
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
index 57a9ce5..ba44435 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
@@ -75,7 +75,7 @@
       Matcher matcher = pattern.matcher(message);
       associationPolicy = entry.getValue();
       if (matcher.find()) {
-        issueId = extractMatchedWorkItems(matcher);
+        issueId = issueExtractor.extractMatchedWorkItems(matcher);
         log.debug("Pattern matched on comment '{}' with issue id '{}'",
             message.trim(), issueId);
         break;
@@ -150,15 +150,6 @@
     return regexMap;
   }
 
-  private String extractMatchedWorkItems(Matcher matcher) {
-    int groupCount = matcher.groupCount();
-    if (groupCount >= 1)
-      return matcher.group(1);
-    else
-      return null;
-  }
-
-
   @Override
   public List<CommitValidationMessage> onCommitReceived(
       CommitReceivedEvent receiveEvent) throws CommitValidationException {