@@ -112,7 +112,6 @@ def accept_mr(
112112 self ,
113113 merge_request ,
114114 expected_remote_target_branch_sha ,
115- source_repo_url = None ,
116115 ):
117116 log .info ('Fusing MR !%s' , merge_request .iid )
118117 approvals = merge_request .fetch_approvals ()
@@ -122,21 +121,6 @@ def accept_mr(
122121 if new_target_sha != expected_remote_target_branch_sha :
123122 raise CannotBatch ('Someone was naughty and by-passed marge' )
124123
125- # FIXME: we should only add tested-by for the last MR in the batch
126- _ , _ , actual_sha = self .update_from_target_branch_and_push (
127- merge_request ,
128- source_repo_url = source_repo_url ,
129- )
130-
131- sha_now = Commit .last_on_branch (
132- merge_request .source_project_id , merge_request .source_branch , self ._api ,
133- ).id
134- # Make sure no-one managed to race and push to the branch in the
135- # meantime, because we're about to impersonate the approvers, and
136- # we don't want to approve unreviewed commits
137- if sha_now != actual_sha :
138- raise CannotMerge ('Someone pushed to branch while we were trying to merge' )
139-
140124 # As we're not using the API to merge the MR, we don't strictly need to reapprove it. However,
141125 # it's a little weird to look at the merged MR to find it has no approvals, so let's do it anyway.
142126 self .maybe_reapprove (merge_request , approvals )
@@ -198,6 +182,9 @@ def execute(self):
198182 merge_request .source_branch ,
199183 '%s/%s' % (merge_request_remote , merge_request .source_branch ),
200184 )
185+ # Apply the trailers before running the batch MR
186+ self .add_trailers (merge_request )
187+ self .push_force_to_mr (merge_request , True , source_repo_url , skip_ci = True )
201188
202189 # Update <source_branch> on latest <batch> branch so it contains previous MRs
203190 self .fuse (
@@ -207,6 +194,9 @@ def execute(self):
207194 local = True ,
208195 )
209196
197+ # Ensure that individual branch commit SHA matches matches that of its equivalent in batch MR
198+ self .push_force_to_mr (merge_request , True , source_repo_url , skip_ci = True )
199+
210200 # Update <batch> branch with MR changes
211201 self ._repo .fast_forward (
212202 BatchMergeJob .BATCH_BRANCH_NAME ,
@@ -225,36 +215,34 @@ def execute(self):
225215 working_merge_requests .append (merge_request )
226216 if len (working_merge_requests ) <= 1 :
227217 raise CannotBatch ('not enough ready merge requests' )
228- if self ._project .only_allow_merge_if_pipeline_succeeds :
229- # This switches git to <batch> branch
230- self .push_batch ()
231- batch_mr = self .create_batch_mr (
232- target_branch = target_branch ,
233- )
218+ # This switches git to <batch> branch
219+ self .push_batch ()
220+ batch_mr = self .create_batch_mr (
221+ target_branch = target_branch ,
222+ )
223+ for merge_request in working_merge_requests :
224+ merge_request .comment ('I will attempt to batch this MR (!{})...' .format (batch_mr .iid ))
225+ try :
226+ self .wait_for_ci_to_pass (batch_mr )
227+ except CannotMerge as err :
234228 for merge_request in working_merge_requests :
235- merge_request .comment ('I will attempt to batch this MR (!{})...' .format (batch_mr .iid ))
236- try :
237- self .wait_for_ci_to_pass (batch_mr )
238- except CannotMerge as err :
239- for merge_request in working_merge_requests :
240- merge_request .comment (
241- 'Batch MR !{batch_mr_iid} failed: {error} I will retry later...' .format (
242- batch_mr_iid = batch_mr .iid ,
243- error = err .reason ,
244- ),
245- )
246- raise CannotBatch (err .reason ) from err
229+ merge_request .comment (
230+ 'Batch MR !{batch_mr_iid} failed: {error} I will retry later...' .format (
231+ batch_mr_iid = batch_mr .iid ,
232+ error = err .reason ,
233+ ),
234+ )
235+ raise CannotBatch (err .reason ) from err
247236 for merge_request in working_merge_requests :
248237 try :
249238 # FIXME: this should probably be part of the merge request
250239 _ , source_repo_url , merge_request_remote = self .fetch_source_project (merge_request )
251- self .ensure_mr_not_changed (merge_request )
252240 self .ensure_mergeable_mr (merge_request )
253- remote_target_branch_sha = self . accept_mr (
254- merge_request ,
255- remote_target_branch_sha ,
256- source_repo_url = source_repo_url ,
257- )
241+ if merge_request == working_merge_requests [ - 1 ]:
242+ self . accept_mr (
243+ batch_mr ,
244+ remote_target_branch_sha ,
245+ )
258246 except CannotBatch as err :
259247 merge_request .comment (
260248 "I couldn't merge this branch: {error} I will retry later..." .format (
0 commit comments