From 3825c02fa963ade0cc8cb272582758c1ad24e17f Mon Sep 17 00:00:00 2001 From: Harry Lee Date: Mon, 27 Jul 2020 15:12:32 +0000 Subject: [PATCH] add trailers before create the batch MR --- .gitignore | 3 +++ marge/batch_job.py | 10 ++++++++-- marge/job.py | 6 +++--- marge/single_merge_job.py | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6b92becc..b7e49fd4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ ENV/ # nix stuff result result-* + +# Editor +*.sw[po] diff --git a/marge/batch_job.py b/marge/batch_job.py index 2f4cae82..b49f901a 100644 --- a/marge/batch_job.py +++ b/marge/batch_job.py @@ -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( @@ -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 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) @@ -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 on latest branch so it contains previous MRs self.fuse( merge_request.source_branch, @@ -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') diff --git a/marge/job.py b/marge/job.py index b2a22b81..b5ab3100 100644 --- a/marge/job.py +++ b/marge/job.py @@ -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 @@ -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) diff --git a/marge/single_merge_job.py b/marge/single_merge_job.py index f4ed83ef..75dc2c59 100644 --- a/marge/single_merge_job.py +++ b/marge/single_merge_job.py @@ -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