Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ def regexp(str_regex):
help='Use merge commit when creating batches, so that the commits in the batch MR '
'will be the same with in individual MRs. Requires sudo scope in the access token.\n',
)
parser.add_argument(
'--batch-branch-suffixing',
action='store_true',
help='Add target branch identifier of first pull request to batch request name',
)
parser.add_argument(
'--skip-ci-batches',
action='store_true',
Expand Down Expand Up @@ -342,6 +347,7 @@ def main(args=None):
use_no_ff_batches=options.use_no_ff_batches,
use_merge_commit_batches=options.use_merge_commit_batches,
skip_ci_batches=options.skip_ci_batches,
batch_branch_suffixing=options.batch_branch_suffixing
),
batch=options.batch,
cli=options.cli,
Expand Down
22 changes: 13 additions & 9 deletions marge/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ class BatchMergeJob(MergeJob):
def __init__(self, *, api, user, project, repo, options, merge_requests):
super().__init__(api=api, user=user, project=project, repo=repo, options=options)
self._merge_requests = merge_requests
self._batch_branch_name = BatchMergeJob.BATCH_BRANCH_NAME
if options.batch_branch_suffixing:
suffix = self._merge_requests[0].target_branch
self._batch_branch_name += "/" + suffix

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

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',
Expand All @@ -50,10 +54,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,
Expand Down Expand Up @@ -96,7 +100,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)
Expand Down Expand Up @@ -218,7 +222,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,
Expand All @@ -243,7 +247,7 @@ def execute(self):
)
# Update <batch> 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)' % (
Expand All @@ -257,13 +261,13 @@ def execute(self):
# Update <source_branch> on latest <batch> 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 <batch> 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,
)
Expand Down
3 changes: 3 additions & 0 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ class Fusion(enum.Enum):
'use_no_ff_batches',
'use_merge_commit_batches',
'skip_ci_batches',
'batch_branch_suffixing',
]


Expand All @@ -476,6 +477,7 @@ def default(
add_tested=False, add_part_of=False, add_reviewers=False, reapprove=False,
approval_timeout=None, embargo=None, ci_timeout=None, fusion=Fusion.rebase,
use_no_ff_batches=False, use_merge_commit_batches=False, skip_ci_batches=False,
batch_branch_suffixing=False
):
approval_timeout = approval_timeout or timedelta(seconds=0)
embargo = embargo or IntervalUnion.empty()
Expand All @@ -492,6 +494,7 @@ def default(
use_no_ff_batches=use_no_ff_batches,
use_merge_commit_batches=use_merge_commit_batches,
skip_ci_batches=skip_ci_batches,
batch_branch_suffixing=batch_branch_suffixing,
)


Expand Down
1 change: 1 addition & 0 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def test_default(self):
use_no_ff_batches=False,
use_merge_commit_batches=False,
skip_ci_batches=False,
batch_branch_suffixing=False,
)

def test_default_ci_time(self):
Expand Down