Skip to content

Commit

Permalink
add trailers before create the batch MR
Browse files Browse the repository at this point in the history
  • Loading branch information
tclh123 authored and bostik committed Oct 6, 2020
1 parent ca64531 commit 3825c02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ ENV/
# nix stuff
result
result-*

# Editor
*.sw[po]
10 changes: 8 additions & 2 deletions marge/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def accept_mr(
if new_target_sha != expected_remote_target_branch_sha:
raise CannotBatch('Someone was naughty and by-passed marge')

# FIXME: we should only add tested-by for the last MR in the batch
_, _, actual_sha = self.update_from_target_branch_and_push(
merge_request,
source_repo_url=source_repo_url,
add_trailers=False
)

sha_now = Commit.last_on_branch(
Expand All @@ -154,13 +154,13 @@ def accept_mr(
# it's a little weird to look at the merged MR to find it has no approvals, so let's do it anyway.
self.maybe_reapprove(merge_request, approvals)

# Merge and push directly to avoid run pipelines again.
# This switches git to <target_branch>
final_sha = self.merge_batch(
merge_request.target_branch,
merge_request.source_branch,
self._options.use_no_ff_batches,
)

# Don't force push in case the remote has changed.
self._repo.push(merge_request.target_branch, force=False)

Expand Down Expand Up @@ -213,6 +213,10 @@ def execute(self):
'%s/%s' % (merge_request_remote, merge_request.source_branch),
)

# Apply the trailers before running the batch MR
actual_sha = self.add_trailers(merge_request)
self.push_force_to_mr(merge_request, branch_was_modified=True, source_repo_url=source_repo_url)

# Update <source_branch> on latest <batch> branch so it contains previous MRs
self.fuse(
merge_request.source_branch,
Expand All @@ -236,6 +240,8 @@ def execute(self):
log.warning('Skipping MR !%s, got conflicts while rebasing', merge_request.iid)
continue
else:
# update merge_request with the latest sha
merge_request.refetch_info()
working_merge_requests.append(merge_request)
if len(working_merge_requests) <= 1:
raise CannotBatch('not enough ready merge requests')
Expand Down
6 changes: 3 additions & 3 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def fuse(self, source, target, source_repo_url=None, local=False):
def update_from_target_branch_and_push(
self,
merge_request,
*,
source_repo_url=None,
add_trailers=True,
):
"""Updates `target_branch` with commits from `source_branch`, optionally add trailers and push.
"""Updates `source_branch` on `target_branch`, optionally add trailers and push.
The update strategy can either be rebase or merge. The default is rebase.
Returns
Expand Down Expand Up @@ -296,7 +296,7 @@ def update_from_target_branch_and_push(
target_sha = repo.get_commit_hash('origin/' + target_branch)
if updated_sha == target_sha:
raise CannotMerge('these changes already exist in branch `{}`'.format(target_branch))
final_sha = self.add_trailers(merge_request) or updated_sha
final_sha = add_trailers and self.add_trailers(merge_request) or updated_sha
commits_rewrite_done = True
branch_was_modified = final_sha != initial_mr_sha
self.synchronize_mr_with_local_changes(merge_request, branch_was_modified, source_repo_url)
Expand Down
3 changes: 2 additions & 1 deletion marge/single_merge_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def update_merge_request_and_accept(self, approvals):
self.ensure_mergeable_mr(merge_request)

try:
merge_request.accept(
ret = merge_request.accept(
remove_branch=merge_request.force_remove_source_branch,
sha=actual_sha,
merge_when_pipeline_succeeds=bool(target_project.only_allow_merge_if_pipeline_succeeds),
)
log.info('merge_request.accept result: %s', ret)
except gitlab.NotAcceptable as err:
new_target_sha = Commit.last_on_branch(self._project.id, merge_request.target_branch, api).id
# target_branch has moved under us since we updated, just try again
Expand Down

0 comments on commit 3825c02

Please sign in to comment.