From 211ff9c67f8226cb482b70f317d926c3b4c906b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2024 13:07:21 +0200 Subject: [PATCH 1/4] Fail for backports with "Affects v9.x" labels set Backports are not expected to have any "Affects v9.x" labels set since those are only meant to be set for merge requests that should have backports created for them. (cherry picked from commit 9359cb9c99454626b65b3863e10e710a329ca99c) --- dangerfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dangerfile.py b/dangerfile.py index 6ed0e0bf10..5dd2f18c51 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -164,6 +164,8 @@ if not danger.gitlab.mr.milestone: # # FAIL if any of the following is true for the merge request: # +# * The MR is marked as a Backport and has any "Affects v9.x" label(s) set. +# # * The MR is marked as Backport and the number of version labels set is # different than 1. (For backports, the version label is used for indicating # its target branch. This is a rather ugly attempt to address a UI @@ -187,6 +189,8 @@ VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?") 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 affects_labels: + fail("Backports must not have any *Affects v9.x* labels set.") if len(version_labels) != 1: fail( "This MR was marked as *Backport*. " From df4d0479d2a91556ec5b9f4424ea1e6775a0d22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2024 13:07:21 +0200 Subject: [PATCH 2/4] Fail for branches using old-style version suffixes Using "-v9_x" and "-v9.x" version suffixes for branch names is now deprecated since some automation logic does not handle these. Fail for any merge request using such old-style version suffixes. (cherry picked from commit 09851e62309f55bb3e6e3bc7299db95929827f76) --- dangerfile.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dangerfile.py b/dangerfile.py index 5dd2f18c51..81eca5f583 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -49,6 +49,7 @@ affected_files = ( danger.git.modified_files + danger.git.created_files + danger.git.deleted_files ) mr_labels = danger.gitlab.mr.labels +source_branch = danger.gitlab.mr.source_branch 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 @@ -60,6 +61,23 @@ gl = gitlab.Gitlab( proj = gl.projects.get(os.environ["CI_PROJECT_ID"]) mr = proj.mergerequests.get(os.environ["CI_MERGE_REQUEST_IID"]) +############################################################################### +# BRANCH NAME +############################################################################### +# +# - FAIL if the source branch of the merge request includes an old-style +# "-v9_x" or "-v9.x" suffix. + +branch_name_regex = r"^(?P.*?)(?P-v9[_.](?P[0-9]+))$" +match = re.match(branch_name_regex, source_branch) +if match: + fail( + f"Source branch name `{source_branch}` includes an old-style version " + f"suffix (`{match.group('suffix')}`). Using such suffixes is now " + "deprecated. Please resubmit the merge request with the branch name " + f"set to `{match.group('base')}-bind-9.{match.group('version')}`." + ) + ############################################################################### # COMMIT MESSAGES ############################################################################### From 8482c3590e8eb7dd4c962635ff04e6f244e319aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2024 13:07:21 +0200 Subject: [PATCH 3/4] Warn about auto-generated merge request titles Merge request titles auto-generated by GitLab are often a source of confusion regarding the actual contents of a given merge request. Warn for merge requests containing titles that look like auto-generated ones. (cherry picked from commit 80ec57f198e5706e653ebe2016f41dc6f856db8c) --- dangerfile.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dangerfile.py b/dangerfile.py index 81eca5f583..d267572fa5 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -48,6 +48,7 @@ modified_files = danger.git.modified_files affected_files = ( danger.git.modified_files + danger.git.created_files + danger.git.deleted_files ) +mr_title = danger.gitlab.mr.title mr_labels = danger.gitlab.mr.labels source_branch = danger.gitlab.mr.source_branch target_branch = danger.gitlab.mr.target_branch @@ -61,6 +62,19 @@ gl = gitlab.Gitlab( proj = gl.projects.get(os.environ["CI_PROJECT_ID"]) mr = proj.mergerequests.get(os.environ["CI_MERGE_REQUEST_IID"]) +############################################################################### +# MERGE REQUEST INFORMATION +############################################################################### +# +# - WARN if the merge request's title looks like an auto-generated one. + +if mr_title.replace("Draft: ", "").startswith('Resolve "'): + warn( + f"This merge request's title (`{mr_title}`) looks like an " + "auto-generated one. Please change it so that it accurately " + "describes the changes contained in this merge request." + ) + ############################################################################### # BRANCH NAME ############################################################################### @@ -218,7 +232,7 @@ if is_backport: 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) + match = re.search(title_re, mr_title) if match is None: fail( "Backport MRs must have their target version in the title. " From c1fb781de854f7c51d4901930cae9338ed7888e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2024 13:07:21 +0200 Subject: [PATCH 4/4] Fail for merge requests with "Affects v9.x" labels Setting "Affects v9.x" labels on a merge request duplicates information already present on the GitLab issue associated with that merge request. For trivial merge requests that are not associated with any GitLab issue, setting the "Affects v9.x" label(s) is considered unnecessary. Trigger a failure for every merge request marked with at least one "Affects v9.x" label. (cherry picked from commit aae51cf28d4466907e152591c8a00525f7ec7038) --- dangerfile.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index d267572fa5..ab69fa99b5 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -196,7 +196,8 @@ if not danger.gitlab.mr.milestone: # # FAIL if any of the following is true for the merge request: # -# * The MR is marked as a Backport and has any "Affects v9.x" label(s) set. +# * The MR has any "Affects v9.x" label(s) set. These should only be used for +# issues. # # * The MR is marked as Backport and the number of version labels set is # different than 1. (For backports, the version label is used for indicating @@ -220,9 +221,12 @@ BACKPORT_OF_RE = re.compile( VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?") 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 affects_labels: + fail( + "This MR is marked with at least one *Affects v9.x* label. " + "Please remove them as they should only be used for issues." + ) if is_backport: - if affects_labels: - fail("Backports must not have any *Affects v9.x* labels set.") if len(version_labels) != 1: fail( "This MR was marked as *Backport*. " @@ -281,11 +285,6 @@ else: "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