From 9359cb9c99454626b65b3863e10e710a329ca99c 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. --- dangerfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dangerfile.py b/dangerfile.py index cb04aeb384..fe0d2ad0a3 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -167,6 +167,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 @@ -190,6 +192,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 09851e62309f55bb3e6e3bc7299db95929827f76 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. --- dangerfile.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dangerfile.py b/dangerfile.py index fe0d2ad0a3..c3f63688b3 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -52,6 +52,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 @@ -63,6 +64,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 80ec57f198e5706e653ebe2016f41dc6f856db8c 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. --- dangerfile.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dangerfile.py b/dangerfile.py index c3f63688b3..5970976e85 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -51,6 +51,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 @@ -64,6 +65,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 ############################################################################### @@ -221,7 +235,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 aae51cf28d4466907e152591c8a00525f7ec7038 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. --- dangerfile.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 5970976e85..fff5b2ac65 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -199,7 +199,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 @@ -223,9 +224,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*. " @@ -284,11 +288,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