From 8bc806a9f2f0c512d871218fb5e1b8b8d8c68445 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Mon, 19 Dec 2022 14:43:16 +0100 Subject: [PATCH 1/2] danger: check version in MR title Enforce the version indicator to be at the start of the MR title. (cherry picked from commit d1172e011c32f3708422557ad5fdbee00e6fb7dd) --- dangerfile.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 76fe5e91d2..7ad682c53f 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -174,6 +174,7 @@ if not danger.gitlab.mr.milestone: BACKPORT_OF_RE = re.compile( r"Backport\s+of.*(merge_requests/|!)([0-9]+)", flags=re.IGNORECASE ) +VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?") 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: @@ -183,11 +184,14 @@ if is_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: + minor_ver, edition = VERSION_LABEL_RE.search(version_labels[0]).groups() + edition = "" if edition is None else edition + title_re = f"^\\[9.{minor_ver}{edition}\\]" + match = re.search(title_re, danger.gitlab.mr.title) + if match is None: fail( - "Backport MRs must have their target branch in the " - f"title. Please put `{mr_title_version}` in the MR title." + "Backport MRs must have their target version in the title. " + f"Please put `[9.{minor_ver}{edition}]` at the start of the MR title." ) if backport_desc is None: fail( From 893d6dc98f5bd172ad7238afab3b8b457ee6554e Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Mon, 19 Dec 2022 15:14:48 +0100 Subject: [PATCH 2/2] danger: check the Affects labels are set Unless the MR is a backport, the Affects labels should be used to indicate which versions are affected by the issue that prompted the MR. (cherry picked from commit 64d71a1f5f13aec1bf380c06c404f3ae8f49684e) --- dangerfile.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 7ad682c53f..405282adf4 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -177,6 +177,7 @@ BACKPORT_OF_RE = re.compile( VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?") backport_desc = BACKPORT_OF_RE.search(danger.gitlab.mr.description) version_labels = [l for l in mr_labels if l.startswith("v9.")] +affects_labels = [l for l in mr_labels if l.startswith("Affects v9.")] if is_backport: if len(version_labels) != 1: fail( @@ -228,12 +229,18 @@ if is_backport: "commits are meant to be backported." ) fail(msg) -if not is_backport and not version_labels: - fail( - "If this merge request is a backport, set the *Backport* label and " - "a single version label (*v9.x*) indicating the target branch. " - "If not, set version labels for all targeted backport branches." - ) +else: + if not version_labels: + fail( + "If this merge request is a backport, set the *Backport* label and " + "a single version label (*v9.x*) indicating the target branch. " + "If not, set version labels for all targeted backport branches." + ) + if not affects_labels: + warn( + "Set `Affects v9.` label(s) for all versions that are affected by " + "the issue which this MR addresses." + ) ############################################################################### # OTHER LABELS