Switch to Zuul's regular expression for `Depends-On` detection

Since `Depends-On` is ultimately for Zuul (the service), there is no
point in being stricter or less strict that Zuul is. Otherwise, the UI
would not reflect what Zuul can pick up or fails to pick up. This would
be confusing for users.

For reference, Zuul's regular expression for `Depends-On` detection is
here:

  https://opendev.org/zuul/zuul/src/commit/041e251b7c3d76f7cc89e491f2ed246b87b1cd9c/zuul/driver/gerrit/gerritconnection.py#L477

Change-Id: Idf421a6e1a29e21883540d49cf5ccc8190ffec17
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractor.java
index 92521a5..456eacf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractor.java
@@ -22,7 +22,9 @@
 public class DependsOnExtractor {
   public List<String> extract(String commitMessage) {
     List<String> dependsOn = new ArrayList<>();
-    Pattern pattern = Pattern.compile("[Dd]epends-[Oo]n:? (I[0-9a-f]{8,40})", Pattern.DOTALL);
+    Pattern pattern =
+        Pattern.compile(
+            "^Depends-On: (I[0-9a-f]{40})\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
     Matcher matcher = pattern.matcher(commitMessage);
     while (matcher.find()) {
       String key = matcher.group(1);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractorTest.java
index 7e24229..70344f7 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/zuul/util/DependsOnExtractorTest.java
@@ -30,7 +30,27 @@
   }
 
   @Test
-  public void testExtractSingleDependency() throws Exception {
+  public void testExtractNoDependencyTooShortChangeId() throws Exception {
+    DependsOnExtractor extractor = new DependsOnExtractor();
+    String commitMessage = "subject\n\nDepends-On: I123456789112345678921234567893123456789";
+
+    List<String> extracted = extractor.extract(commitMessage);
+
+    assertThat(extracted).isEmpty();
+  }
+
+  @Test
+  public void testExtractNoDependencyTooLongChangeId() throws Exception {
+    DependsOnExtractor extractor = new DependsOnExtractor();
+    String commitMessage = "subject\n\nDepends-On: I12345678911234567892123456789312345678941";
+
+    List<String> extracted = extractor.extract(commitMessage);
+
+    assertThat(extracted).isEmpty();
+  }
+
+  @Test
+  public void testExtractSingleDependencyLineEnd() throws Exception {
     DependsOnExtractor extractor = new DependsOnExtractor();
     String commitMessage = "subject\n\nDepends-On: " + getChangeKey(1);
 
@@ -40,6 +60,16 @@
   }
 
   @Test
+  public void testExtractSingleDependencyContinuedLine() throws Exception {
+    DependsOnExtractor extractor = new DependsOnExtractor();
+    String commitMessage = "subject\n\nDepends-On: " + getChangeKey(1) + " ";
+
+    List<String> extracted = extractor.extract(commitMessage);
+
+    assertThat(extracted).containsExactly(getChangeKey(1));
+  }
+
+  @Test
   public void testExtractMultipleDependencies() throws Exception {
     DependsOnExtractor extractor = new DependsOnExtractor();
     String commitMessage =
@@ -69,7 +99,7 @@
   public void testExtractMixedCases() throws Exception {
     DependsOnExtractor extractor = new DependsOnExtractor();
     String commitMessage =
-        "subject\n\ndepends-On: " + getChangeKey(1) + "\nDepends-on: " + getChangeKey(2);
+        "subject\n\ndepends-On: " + getChangeKey(1) + "\nDePeNds-on: " + getChangeKey(2);
 
     List<String> extracted = extractor.extract(commitMessage);