]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use approve button workflow in danger CI
authorTom Krizek <tkrizek@isc.org>
Fri, 4 Nov 2022 12:05:29 +0000 (13:05 +0100)
committerTom Krizek <tkrizek@isc.org>
Tue, 8 Nov 2022 13:34:56 +0000 (14:34 +0100)
Since the LGTM label was deprecated in favor of using the Approve button
in gitlab, adjust the detection in danger bot.

Unfortunately, danger-python seems no longer maintained since 2020 and
MR approvals aren't available in its Python API (even though they're
supported in its Ruby/JS APIs). Going forward, let's use the more
comprehensive python-gitlab API.

It still makes sense to utilize the danger-python, since it handles the
integration with gitlab which doesn't need to be reimplemented as long
as it works - same with the other checks.

dangerfile.py

index 2f139f79aa12bda178bd861ea251975596f6f7d7..c8b495785e86cc47c429d7ae678f088a3a59616f 100644 (file)
 # information regarding copyright ownership.
 ############################################################################
 
+import os
 import re
 
+import gitlab
+
 # Helper functions and variables
 
 
@@ -44,6 +47,13 @@ modified_files = danger.git.modified_files
 mr_labels = danger.gitlab.mr.labels
 target_branch = danger.gitlab.mr.target_branch
 
+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
 ###############################################################################
@@ -167,15 +177,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."
     )
 
 ###############################################################################