@@ -20,16 +20,17 @@ def __init__(self, *, api, user, project, repo, options, merge_requests):
20
20
super ().__init__ (api = api , user = user , project = project , repo = repo , options = options )
21
21
self ._merge_requests = merge_requests
22
22
23
- def remove_batch_branch (self ):
23
+ def remove_batch_branch (self , target_branch ):
24
24
log .info ('Removing local batch branch' )
25
25
try :
26
- self ._repo .remove_branch (BatchMergeJob .BATCH_BRANCH_NAME )
26
+ self ._repo .remove_branch (f' { BatchMergeJob .BATCH_BRANCH_NAME } / { target_branch } ' )
27
27
except git .GitError :
28
28
pass
29
29
30
- def close_batch_mr (self ):
30
+ def close_batch_mr (self , target_branch ):
31
31
log .info ('Closing batch MRs' )
32
32
params = {
33
+ 'target_branch' : target_branch ,
33
34
'author_id' : self ._user .id ,
34
35
'labels' : BatchMergeJob .BATCH_BRANCH_NAME ,
35
36
'state' : 'opened' ,
@@ -48,7 +49,7 @@ def close_batch_mr(self):
48
49
def create_batch_mr (self , target_branch ):
49
50
log .info ('Creating batch MR' )
50
51
params = {
51
- 'source_branch' : BatchMergeJob .BATCH_BRANCH_NAME ,
52
+ 'source_branch' : f' { BatchMergeJob .BATCH_BRANCH_NAME } / { target_branch } ' ,
52
53
'target_branch' : target_branch ,
53
54
'title' : 'Marge Bot Batch MR - DO NOT TOUCH' ,
54
55
'labels' : BatchMergeJob .BATCH_BRANCH_NAME ,
@@ -92,9 +93,9 @@ def get_mergeable_mrs(self, merge_requests):
92
93
mergeable_mrs .append (merge_request )
93
94
return mergeable_mrs
94
95
95
- def push_batch (self ):
96
+ def push_batch (self , target_branch ):
96
97
log .info ('Pushing batch branch' )
97
- self ._repo .push (BatchMergeJob .BATCH_BRANCH_NAME , force = True )
98
+ self ._repo .push (f' { BatchMergeJob .BATCH_BRANCH_NAME } / { target_branch } ' , force = True )
98
99
99
100
def ensure_mr_not_changed (self , merge_request ):
100
101
log .info ('Ensuring MR !%s did not change' , merge_request .iid )
@@ -181,11 +182,13 @@ def accept_mr(
181
182
return final_sha
182
183
183
184
def execute (self ):
184
- # Cleanup previous batch work
185
- self .remove_batch_branch ()
186
- self .close_batch_mr ()
187
185
188
186
target_branch = self ._merge_requests [0 ].target_branch
187
+
188
+ # Cleanup previous batch work
189
+ self .remove_batch_branch (target_branch )
190
+ self .close_batch_mr (target_branch )
191
+
189
192
merge_requests = self .get_mrs_with_common_target_branch (target_branch )
190
193
merge_requests = self .get_mergeable_mrs (merge_requests )
191
194
@@ -201,7 +204,8 @@ def execute(self):
201
204
remote_target_branch_sha = self ._repo .get_commit_hash ('origin/%s' % target_branch )
202
205
203
206
self ._repo .checkout_branch (target_branch , 'origin/%s' % target_branch )
204
- self ._repo .checkout_branch (BatchMergeJob .BATCH_BRANCH_NAME , 'origin/%s' % target_branch )
207
+ self ._repo .checkout_branch (f'{ BatchMergeJob .BATCH_BRANCH_NAME } /{ target_branch } ' ,
208
+ 'origin/%s' % target_branch )
205
209
206
210
working_merge_requests = []
207
211
@@ -241,7 +245,7 @@ def execute(self):
241
245
raise CannotBatch ('not enough ready merge requests' )
242
246
if self ._project .only_allow_merge_if_pipeline_succeeds :
243
247
# This switches git to <batch> branch
244
- self .push_batch ()
248
+ self .push_batch (target_branch )
245
249
batch_mr = self .create_batch_mr (
246
250
target_branch = target_branch ,
247
251
)
0 commit comments