aboutsummaryrefslogtreecommitdiff
path: root/labbot/addons
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-09-07 09:52:37 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-09-07 09:52:37 +0200
commit256aeeee6077da0a28bcc2fb19ab7923e472d26a (patch)
treedec941fb85041945e186d007b5150459b7f13223 /labbot/addons
parentec850ccb99d3ebfb8a69483de868097ed8288f7f (diff)
downloadlab-bot-256aeeee6077da0a28bcc2fb19ab7923e472d26a.tar.gz
lab-bot-256aeeee6077da0a28bcc2fb19ab7923e472d26a.zip
add per repository settings
Diffstat (limited to 'labbot/addons')
-rw-r--r--labbot/addons/approve-merge.py12
-rw-r--r--labbot/addons/merge-label.py54
-rw-r--r--labbot/addons/merge-stable.py26
3 files changed, 55 insertions, 37 deletions
diff --git a/labbot/addons/approve-merge.py b/labbot/addons/approve-merge.py
index 9b10ef6..9c6eceb 100644
--- a/labbot/addons/approve-merge.py
+++ b/labbot/addons/approve-merge.py
@@ -4,10 +4,16 @@ is reached.
"""
import logging
+from labbot.config import Config
+
log = logging.getLogger(__name__)
-required_approval_count = 2
+config = Config(__name__)
+config.set_global_data(
+ required_approval_count = 2
+)
+@config.config_decorator()
async def merge_label_hook(event, gl, *args, **kwargs):
title = event.object_attributes["title"]
state = event.object_attributes["state"]
@@ -24,12 +30,12 @@ async def merge_label_hook(event, gl, *args, **kwargs):
approval_count = len(data["approved_by"])
- if approval_count >= required_approval_count:
+ if approval_count >= config["required_approval_count"]:
if merge_status == "can_be_merged":
await gl.put(merge_url)
else:
log.debug(f"Cannot merge !{iid} because of its merge_status `{merge_status}`")
def setup(bot):
+ config.setup(__name__, bot.name)
bot.register_merge_hook(merge_label_hook)
- pass \ No newline at end of file
diff --git a/labbot/addons/merge-label.py b/labbot/addons/merge-label.py
index a978388..746e236 100644
--- a/labbot/addons/merge-label.py
+++ b/labbot/addons/merge-label.py
@@ -7,29 +7,34 @@ import os
import re
import logging
-log = logging.getLogger(__name__)
-
-
-title_regex = r"^(?:#|)(\d+)\s*"
-word_regex = r"^#(\d+)$"
-relation_keywords = [
- "related"
-]
-relation_distance = 2
+from labbot.config import Config
-state_label = {
- "closed": "In Progress",
- "opened": "Code-Review",
- "merged": "C-R Bestanden",
-}
-
-# Extra labels that the bot will check for before acting
-act_labels = [
- "Sprint",
- "Testing",
- "TestingFailed",
-]
+log = logging.getLogger(__name__)
+config = Config(__name__)
+config.set_global_data(
+ title_regex = r"^(?:#|)(\d+)\s*",
+ word_regex = r"^#(\d+)$",
+
+ relation_keywords = [
+ "related"
+ ],
+ relation_distance = 2,
+
+ state_label = {
+ "closed": "In Progress",
+ "opened": "Code-Review",
+ "merged": "C-R Bestanden",
+ },
+
+ act_labels = [
+ "Sprint",
+ "Testing",
+ "TestingFailed",
+ ]
+)
+
+@config.config_decorator()
async def merge_label_hook(event, gl, *args, **kwargs):
title = event.object_attributes["title"]
description = event.object_attributes["description"]
@@ -75,7 +80,7 @@ async def merge_label_hook(event, gl, *args, **kwargs):
has_label = False
issue_data = await gl.getitem(base_url)
for label in issue_data["labels"]:
- if label in act_labels or label in state_label.values():
+ if label in act_labels or label in config["state_label"].values():
has_label = True
break
@@ -83,10 +88,10 @@ async def merge_label_hook(event, gl, *args, **kwargs):
log.debug(f"Issue #{issue} does not have a relevant label")
continue
- delete_labels = act_labels + list(state_label.values())
+ delete_labels = act_labels + list(config["state_label"].values())
try:
- label = state_label[state]
+ label = config["state_label"][state]
if label in delete_labels:
delete_labels.remove(label)
@@ -103,4 +108,5 @@ async def merge_label_hook(event, gl, *args, **kwargs):
log.exception("Unknown state")
def setup(bot) -> None:
+ config.setup(__name__, bot.name)
bot.register_merge_hook(merge_label_hook)
diff --git a/labbot/addons/merge-stable.py b/labbot/addons/merge-stable.py
index d395160..f8e0ced 100644
--- a/labbot/addons/merge-stable.py
+++ b/labbot/addons/merge-stable.py
@@ -6,13 +6,18 @@ branch relation is figured out by looking at related merge requests
import logging
-log = logging.getLogger(__name__)
+from labbot.config import Config
+log = logging.getLogger(__name__)
-stable_branch = "main"
-staging_branch = "staging"
-merge_label = "Release"
+config = Config()
+config.set_global_data(
+ stable_branch = "main",
+ staging_branch = "staging",
+ merge_label = "Release",
+)
+@config.config_decorator()
async def issue_update_hook(event, gl, *args, **kwargs):
issue_id = event.object_attributes["iid"]
issue_url = f"/projects/{event.project_id}/issues/{issue_id}"
@@ -20,14 +25,14 @@ async def issue_update_hook(event, gl, *args, **kwargs):
branches = {}
- if merge_label in issue_data["labels"]:
+ if config["merge_label"] in issue_data["labels"]:
async for merge_data in gl.getiter(f"{issue_url}/related_merge_requests"):
source_branch = merge_data["source_branch"]
target_branch = merge_data["target_branch"]
merge_id = merge_data["iid"]
# we only want staging merges
- if target_branch != staging_branch:
+ if target_branch != config["staging_branch"]:
continue
if not source_branch in branches:
@@ -44,7 +49,7 @@ async def issue_update_hook(event, gl, *args, **kwargs):
async for merge_data in gl.getiter(merge_url, params={
"source_branch": branch,
- "target_branch": stable_branch
+ "target_branch": config["stable_branch"]
}):
if merge_data["state"] == "opened":
merge_exists = True
@@ -55,11 +60,12 @@ async def issue_update_hook(event, gl, *args, **kwargs):
merge_string = ", ".join(merge)
await gl.post(merge_url, data={
"source_branch": branch,
- "target_branch": stable_branch,
- "title": f"[stable] Merge `{branch}` into `{stable_branch}`",
+ "target_branch": config["stable_branch"],
+ "title": f"[stable] Merge `{branch}` into `{config['stable_branch']}`",
"description": f"Related to #{issue_id} \n \nStaging Merges: \n{merge_string}"
})
def setup(bot) -> None:
- bot.register_issue_hook(issue_update_hook) \ No newline at end of file
+ config.setup(__name__, bot.name)
+ bot.register_issue_hook(issue_update_hook)