From 653bab61bc28c88197dacaf8e31ea7c1e7fdec25 Mon Sep 17 00:00:00 2001 From: Scott Clarke Date: Wed, 26 Oct 2022 16:20:06 +0100 Subject: [PATCH] Remove source branches in batch jobs if necessary In batch jobs source branch deletion can be bypassed, despite the setting being enabled in the original merge request. This change will check if the source branch should be deleted and make the appropriate API call to delete if so --- marge/batch_job.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/marge/batch_job.py b/marge/batch_job.py index faf6b55f..404a5f33 100644 --- a/marge/batch_job.py +++ b/marge/batch_job.py @@ -1,6 +1,7 @@ # pylint: disable=too-many-branches,too-many-statements,arguments-differ import logging as log from time import sleep +from requests.utils import quote from . import git from . import gitlab @@ -9,6 +10,8 @@ from .merge_request import MergeRequest from .pipeline import Pipeline +DELETE = gitlab.DELETE + class CannotBatch(Exception): pass @@ -195,6 +198,16 @@ def accept_mr( for pipeline in pipelines: pipeline.cancel() + if merge_request.force_remove_source_branch: + self._api.call( + DELETE( + 'projects/{}/repository/branches/{}'.format( + merge_request.source_project_id, + quote(merge_request.source_branch, safe='') + ) + ) + ) + return final_sha def execute(self):