diff --git a/marge/batch_job.py b/marge/batch_job.py index faf6b55f..6d8f0e72 100644 --- a/marge/batch_job.py +++ b/marge/batch_job.py @@ -24,7 +24,7 @@ def __init__(self, *, api, user, project, repo, options, merge_requests): def remove_batch_branch(self): log.info('Removing local batch branch') try: - self._repo.remove_branch(BatchMergeJob.BATCH_BRANCH_NAME) + self._repo.remove_branch(self._batch_branch_name) except git.GitError: pass @@ -32,7 +32,7 @@ def close_batch_mr(self): log.info('Closing batch MRs') params = { 'author_id': self._user.id, - 'labels': BatchMergeJob.BATCH_BRANCH_NAME, + 'labels': self._batch_branch_name, 'state': 'opened', 'order_by': 'created_at', 'sort': 'desc', @@ -50,10 +50,10 @@ def create_batch_mr(self, target_branch): self.push_batch() log.info('Creating batch MR') params = { - 'source_branch': BatchMergeJob.BATCH_BRANCH_NAME, + 'source_branch': self._batch_branch_name, 'target_branch': target_branch, 'title': 'Marge Bot Batch MR - DO NOT TOUCH', - 'labels': BatchMergeJob.BATCH_BRANCH_NAME, + 'labels': self._batch_branch_name, } batch_mr = MergeRequest.create( api=self._api, @@ -96,7 +96,7 @@ def get_mergeable_mrs(self, merge_requests): def push_batch(self): log.info('Pushing batch branch') - self._repo.push(BatchMergeJob.BATCH_BRANCH_NAME, force=True) + self._repo.push(self._batch_branch_name, force=True) def ensure_mr_not_changed(self, merge_request): log.info('Ensuring MR !%s did not change', merge_request.iid) @@ -198,6 +198,11 @@ def accept_mr( return final_sha def execute(self): + self._batch_branch_name = (BatchMergeJob.BATCH_BRANCH_NAME + "_" + + self._merge_requests[0].target_branch) + + log.debug("batch: execute: _batch_branch_name: %s", self._batch_branch_name) + # Cleanup previous batch work self.remove_batch_branch() self.close_batch_mr() @@ -218,7 +223,7 @@ def execute(self): remote_target_branch_sha = self._repo.get_commit_hash('origin/%s' % target_branch) self._repo.checkout_branch(target_branch, 'origin/%s' % target_branch) - self._repo.checkout_branch(BatchMergeJob.BATCH_BRANCH_NAME, 'origin/%s' % target_branch) + self._repo.checkout_branch(self._batch_branch_name, 'origin/%s' % target_branch) batch_mr = self.create_batch_mr( target_branch=target_branch, @@ -243,7 +248,7 @@ def execute(self): ) # Update branch with MR changes batch_mr_sha = self._repo.merge( - BatchMergeJob.BATCH_BRANCH_NAME, + self._batch_branch_name, merge_request.source_branch, '-m', 'Batch merge !%s into %s (!%s)' % ( @@ -257,13 +262,13 @@ def execute(self): # Update on latest branch so it contains previous MRs self.fuse( merge_request.source_branch, - BatchMergeJob.BATCH_BRANCH_NAME, + self._batch_branch_name, source_repo_url=source_repo_url, local=True, ) # Update branch with MR changes batch_mr_sha = self._repo.fast_forward( - BatchMergeJob.BATCH_BRANCH_NAME, + self._batch_branch_name, merge_request.source_branch, local=True, )