Skip to content

Commit 4ef4a55

Browse files
committed
Remove source branches is 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
1 parent d3c4409 commit 4ef4a55

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

marge/batch_job.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=too-many-branches,too-many-statements,arguments-differ
22
import logging as log
33
from time import sleep
4+
from requests.utils import quote
45

56
from . import git
67
from . import gitlab
@@ -9,6 +10,8 @@
910
from .merge_request import MergeRequest
1011
from .pipeline import Pipeline
1112

13+
DELETE = gitlab.DELETE
14+
1215

1316
class CannotBatch(Exception):
1417
pass
@@ -195,6 +198,16 @@ def accept_mr(
195198
for pipeline in pipelines:
196199
pipeline.cancel()
197200

201+
if merge_request.force_remove_source_branch:
202+
self._api.call(
203+
DELETE(
204+
'projects/{}/repository/branches/{}'.format(
205+
merge_request.source_project_id,
206+
quote(merge_request.source_branch, safe='')
207+
)
208+
)
209+
)
210+
198211
return final_sha
199212

200213
def execute(self):

0 commit comments

Comments
 (0)