aboutsummaryrefslogtreecommitdiff
path: root/labbot/addons/approve-merge.py
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-05-04 14:25:18 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-05-04 14:25:18 +0200
commit27b8241380d5f02fdcf00a832c281767ef258d9f (patch)
tree7be768b5fa63d928bd886412c0087e97a27b7e44 /labbot/addons/approve-merge.py
parentf73b19f1ab7c32283194907418d6c2d83ed65d06 (diff)
downloadlab-bot-27b8241380d5f02fdcf00a832c281767ef258d9f.tar.gz
lab-bot-27b8241380d5f02fdcf00a832c281767ef258d9f.zip
add approve-merge addon, give addons descriptions
Diffstat (limited to 'labbot/addons/approve-merge.py')
-rw-r--r--labbot/addons/approve-merge.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/labbot/addons/approve-merge.py b/labbot/addons/approve-merge.py
new file mode 100644
index 0000000..0fdeaa9
--- /dev/null
+++ b/labbot/addons/approve-merge.py
@@ -0,0 +1,30 @@
+"""
+automatically merges merge requests if a certain number of approvals
+is reached.
+"""
+
+required_approval_count = 2
+
+async def merge_label_hook(event, gl, *args, **kwargs):
+ title = event.object_attributes["title"]
+ state = event.object_attributes["state"]
+ merge_status = event.object_attributes["merge_status"]
+
+ if state != "opened" or title.lower().startswith("draft"):
+ return
+
+ approvals_url = f"/projects/{event.project_id}/merge_requests/{event.object_attributes['iid']}/approvals"
+ merge_url = f"/projects/{event.project_id}/merge_requests/{event.object_attributes['iid']}/merge"
+
+ data = await gl.getitem(approvals_url)
+
+ approval_count = len(data["approved_by"])
+
+ if approval_count >= required_approval_count:
+ if merge_status == "can_be_merged":
+ print("test")
+ await gl.put(merge_url)
+
+def setup(bot):
+ bot.register(merge_label_hook, "Merge Request Hook")
+ pass \ No newline at end of file