From: Tom Krizek Date: Thu, 15 Dec 2022 16:51:24 +0000 (+0100) Subject: danger: check that original MR has been merged X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57d4fa8e43ff881d4fc6199573272ca6c3eff14e;p=thirdparty%2Fbind9.git danger: check that original MR has been merged When checking a backport MR, ensure that the original MR has been merged already. This is vital for followup checks that verify commit IDs from original commits are present in backport commit messages. (cherry picked from commit 89530f1a1cb2e90b5368605fc317eaed35bf9d1f) --- diff --git a/dangerfile.py b/dangerfile.py index a5fb883c8f3..da41d6e9f7c 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -9,8 +9,11 @@ # information regarding copyright ownership. ############################################################################ +import os import re +import gitlab + # Helper functions and variables def added_lines(target_branch, paths): @@ -37,6 +40,12 @@ target_branch = danger.gitlab.mr.target_branch is_backport = "Backport" in mr_labels or "Backport::Partial" in mr_labels is_full_backport = is_backport and "Backport::Partial" not in mr_labels +gl = gitlab.Gitlab( + url=f"https://{os.environ['CI_SERVER_HOST']}", + private_token=os.environ["DANGER_GITLAB_API_TOKEN"], +) +proj = gl.projects.get(os.environ["CI_PROJECT_ID"]) + ############################################################################### # COMMIT MESSAGES ############################################################################### @@ -131,6 +140,8 @@ if not danger.gitlab.mr.milestone: # * 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. +# +# * The original MR linked to from Backport MR hasn't been merged. BACKPORT_OF_RE = re.compile( r"Backport\s+of.*(merge_requests/|!)([0-9]+)", flags=re.IGNORECASE @@ -155,6 +166,14 @@ if is_backport: "Backport MRs must link to the original MR. Please put " "`Backport of MR !XXXX` in the MR description." ) + else: # backport MR is linked to original MR + original_mr_id = backport_desc.groups()[1] + original_mr = proj.mergerequests.get(original_mr_id) + if original_mr.state != "merged": + fail( + f"Original MR !{original_mr_id} has not been merged. " + "Please re-run `danger` check once it's merged." + ) if not is_backport and not version_labels: fail( "If this merge request is a backport, set the *Backport* label and "