From 14b027cf830020cca6a57f0281bb6da73d118483 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 15 Dec 2022 17:45:54 +0100 Subject: [PATCH] danger: ensure target branch is in the MR title Having the MR title clearly marked in its title can be very useful when looking through older issues/MRs. This check also ensures that the version from the version label matches the proper version branch (i.e. v9.16 must be marked with [v9_16]). --- dangerfile.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 8b1a821534..365fe01a1c 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -171,13 +171,23 @@ if not danger.gitlab.mr.milestone: # * The MR is not marked as "Backport" nor any version label is set. (If the # merge request is not a backport, version labels are used for indicating # backporting preferences.) +# +# * The Backport MR doesn't have target branch in the merge request title. version_labels = [l for l in mr_labels if l.startswith("v9.")] -if is_backport and len(version_labels) != 1: - fail( - "This MR was marked as *Backport*. " - "Please also set exactly one version label (*v9.x*)." - ) +if is_backport: + if len(version_labels) != 1: + fail( + "This MR was marked as *Backport*. " + "Please also set exactly one version label (*v9.x*)." + ) + else: + mr_title_version = f"[{version_labels[0].replace('.', '_')}]" + if mr_title_version not in danger.gitlab.mr.title: + fail( + "Backport MRs must have their target branch in the " + f"title. Please put `{mr_title_version}` in the MR title." + ) if not is_backport and not version_labels: fail( "If this merge request is a backport, set the *Backport* label and "