2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Merge branch 'tkrizek/danger-approve' into 'main'

ci: add danger checks - approve workflow & wip commits

Closes #3651

See merge request isc-projects/bind9!7041
This commit is contained in:
Tom Krizek
2022-11-08 13:37:33 +00:00

View File

@@ -11,8 +11,11 @@
# information regarding copyright ownership.
############################################################################
import os
import re
import gitlab
# Helper functions and variables
@@ -43,6 +46,14 @@ release_notes_regex = re.compile(r"doc/(arm|notes)/notes-.*\.(rst|xml)")
modified_files = danger.git.modified_files
mr_labels = danger.gitlab.mr.labels
target_branch = danger.gitlab.mr.target_branch
backport_label_set = "Backport" 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"])
mr = proj.mergerequests.get(os.environ["CI_MERGE_REQUEST_IID"])
###############################################################################
# COMMIT MESSAGES
@@ -52,6 +63,9 @@ target_branch = danger.gitlab.mr.target_branch
#
# * The subject line starts with "fixup!" or "Apply suggestion".
#
# * The subject line starts with a prohibited word indicating a work in
# progress commit (e.g. "WIP").
#
# * The subject line contains a trailing dot.
#
# * There is no empty line between the subject line and the log message.
@@ -76,7 +90,12 @@ target_branch = danger.gitlab.mr.target_branch
# - lines which contain references (i.e. those starting with "[1]",
# "[2]", etc.) which allows e.g. long URLs to be included in the
# commit log message.
#
# * There is no "cherry picked from X" message in Backport commits.
PROHIBITED_WORDS_RE = re.compile(
"^(WIP|wip|DROP|drop|DROPME|checkpoint|experiment|TODO|todo)[^a-zA-Z]"
)
fixup_error_logged = False
for commit in danger.git.commits:
message_lines = commit.message.splitlines()
@@ -89,6 +108,12 @@ for commit in danger.git.commits:
"Please squash them before merging."
)
fixup_error_logged = True
match = PROHIBITED_WORDS_RE.search(subject)
if match:
fail(
f"Prohibited keyword `{match.groups()[0]}` detected "
f"at the start of a subject line in commit {commit.sha}."
)
if len(subject) > 72 and not subject.startswith("Merge branch "):
warn(
f"Subject line for commit {commit.sha} is too long: "
@@ -115,6 +140,11 @@ for commit in danger.git.commits:
f"Line too long in log message for commit {commit.sha}: "
f"```{line}``` ({len(line)} > 72 characters)."
)
if backport_label_set and "cherry picked from commit" not in commit.message:
warn(
f"`cherry picked from commit...` message missing in commit {commit.sha}. "
"Please use `-x` option with `git cherry-pick` or remove the `Backport` label."
)
###############################################################################
# MILESTONE
@@ -141,7 +171,6 @@ if not danger.gitlab.mr.milestone:
# request is not a backport, version labels are used for indicating
# backporting preferences.)
backport_label_set = "Backport" in mr_labels
version_labels = [l for l in mr_labels if l.startswith("v9.")]
if backport_label_set and len(version_labels) != 1:
fail(
@@ -167,15 +196,16 @@ if not backport_label_set and not version_labels:
# remind developers about the need to set the latter on merge requests which
# passed review.)
approved = mr.approvals.get().approved
if "Review" not in mr_labels:
warn(
"This merge request does not have the *Review* label set. "
"Please set it if you would like the merge request to be reviewed."
)
elif "LGTM (Merge OK)" not in mr_labels:
elif not approved:
warn(
"This merge request is currently in review. "
"It should not be merged until it is marked with the *LGTM* label."
"It should not be merged until it is approved."
)
###############################################################################