]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
danger: check backport links to the original MR
authorTom Krizek <tkrizek@isc.org>
Thu, 15 Dec 2022 16:48:34 +0000 (17:48 +0100)
committerTom Krizek <tkrizek@isc.org>
Fri, 16 Dec 2022 14:06:57 +0000 (15:06 +0100)
When doing archeology, it is much easier to find stuff if it's properly
linked. This check ensures that backport MR are linked to their original
MR via a "Backport of !XXXX" message.

The regular expression is fairly broad and has been tested to accept the
following variants of the message:
Backport of MR !XXXX
Backport of: !XXXX
backport of mr !XXXX
Backport of   !XXXX
Backport of https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/XXXX

(cherry picked from commit 12e0b05738cbd456c8c691fd96364b1ac8b6b259)

dangerfile.py

index 46a8baee5c4e10aee56f7fa5b2866a66b4cf1a18..a5fb883c8f377bb2809f88d45b0e703267b971e0 100644 (file)
@@ -129,7 +129,13 @@ if not danger.gitlab.mr.milestone:
 #   backporting preferences.)
 #
 # * The Backport MR doesn't have target branch in the merge request title.
+#
+# * The Backport MR doesn't link to the original MR is its description.
 
+BACKPORT_OF_RE = re.compile(
+    r"Backport\s+of.*(merge_requests/|!)([0-9]+)", flags=re.IGNORECASE
+)
+backport_desc = BACKPORT_OF_RE.search(danger.gitlab.mr.description)
 version_labels = [l for l in mr_labels if l.startswith("v9.")]
 if is_backport:
     if len(version_labels) != 1:
@@ -144,6 +150,11 @@ if is_backport:
                 "Backport MRs must have their target branch in the "
                 f"title. Please put `{mr_title_version}` in the MR title."
             )
+    if backport_desc is None:
+        fail(
+            "Backport MRs must link to the original MR. Please put "
+            "`Backport of MR !XXXX` in the MR description."
+        )
 if not is_backport and not version_labels:
     fail(
         "If this merge request is a backport, set the *Backport* label and "