aboutsummaryrefslogtreecommitdiff
path: root/labbot
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2024-02-13 11:46:15 +0100
committerJan200101 <sentrycraft123@gmail.com>2024-02-13 11:46:15 +0100
commitecb3f65dff8d8e161e2dc6a8f3a361147dc6ed2d (patch)
treead242868dc92e5dbbc7376cccf3ebc2af1155d3f /labbot
parent0b69d28c9c5715304d3d2a4585dd38927692c092 (diff)
downloadlab-bot-ecb3f65dff8d8e161e2dc6a8f3a361147dc6ed2d.tar.gz
lab-bot-ecb3f65dff8d8e161e2dc6a8f3a361147dc6ed2d.zip
Dont create stable MR when open or more than 3 closed MRs exist
Diffstat (limited to 'labbot')
-rw-r--r--labbot/addons/merge-stable.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/labbot/addons/merge-stable.py b/labbot/addons/merge-stable.py
index a585590..8e4eff6 100644
--- a/labbot/addons/merge-stable.py
+++ b/labbot/addons/merge-stable.py
@@ -45,23 +45,33 @@ async def issue_update_hook(event, gl, *args, **kwargs):
merge_url = f"/projects/{event.project_id}/merge_requests"
for branch, merge in branches.items():
- merges_exists = 0
+ create_stable_merge = True
+ MAX_AVAIL_MERGES = 3
+ merges_exists = 0
async for merge_data in gl.getiter(merge_url, params={
"source_branch": branch,
"target_branch": config["stable_branch"]
}):
- # We found a merge request, add it to the counter
- merges_exists += 1
- if merges_exists > 3:
+ if merge_data["state"] == "opened":
+ # we already have an open MR
+ create_stable_merge = False
+ break
+
+ if merge_data["state"] != "merged":
+ # We found a merge request that has not been merged.
+ # Add it to the counter
+ merges_exists += 1
+
+ # Are there more than MAX_AVAIL_MERGES available merges?
+ # Stop creating new ones for gods sake
+ if merges_exists > MAX_AVAIL_MERGES:
+ create_stable_merge = False
break
- if merges_exists > 3:
+ if create_stable_merge:
log.debug(f"merges for `{branch}` already exists, not opening more than 3")
else:
- if merges_exists:
- log.debug(f"merge for `{branch}` already exists, opening a new one regardless")
-
merge_string = ", ".join(merge)
await gl.post(merge_url, data={
"source_branch": branch,