Skip to content

Commit 830aa81

Browse files
author
David Szervanszky
committed
Add separate flag for optimistic batching
This commit is still missing the logic to ensure that the individual MR hashes and those in the batch MR match
1 parent 4598b2c commit 830aa81

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

marge/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def regexp(str_regex):
208208
action='store_true',
209209
help='Debug logging (includes all HTTP requests etc).\n',
210210
)
211+
parser.add_argument(
212+
'--optimistic-batch',
213+
action='store_true',
214+
help='Experimental optimistic batch (adds trailers to MRs before batching)\n',
215+
)
211216
config = parser.parse_args(args)
212217

213218
if config.use_merge_strategy and config.batch:
@@ -275,6 +280,11 @@ def main(args=None):
275280
if options.batch:
276281
logging.warning('Experimental batch mode enabled')
277282

283+
if options.optimistic_batch:
284+
logging.warning(
285+
'Experimental optimistic batch mode enabled. This may cause undesirable behaviour with respect to MRs.'
286+
)
287+
278288
if options.use_merge_strategy:
279289
fusion = bot.Fusion.merge
280290
elif options.rebase_remotely:
@@ -308,6 +318,7 @@ def main(args=None):
308318
fusion=fusion,
309319
),
310320
batch=options.batch,
321+
optimistic_batch=options.optimistic_batch,
311322
)
312323

313324
marge_bot = bot.Bot(api=api, config=config)

marge/batch_job.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class CannotBatch(Exception):
1616
class BatchMergeJob(MergeJob):
1717
BATCH_BRANCH_NAME = 'marge_bot_batch_merge_job'
1818

19-
def __init__(self, *, api, user, project, repo, options, merge_requests):
19+
def __init__(self, *, api, user, project, repo, options, optimistic, merge_requests):
2020
super().__init__(api=api, user=user, project=project, repo=repo, options=options)
21+
self._optimistic = optimistic
2122
self._merge_requests = merge_requests
2223

2324
def remove_batch_branch(self):
@@ -199,6 +200,10 @@ def execute(self):
199200
'%s/%s' % (merge_request_remote, merge_request.source_branch),
200201
)
201202

203+
# Apply the trailers before running the batch MR
204+
self.add_trailers(merge_request)
205+
self.push_force_to_mr(merge_request, True, source_repo_url, skip_ci=True)
206+
202207
# Update <source_branch> on latest <batch> branch so it contains previous MRs
203208
self.fuse(
204209
merge_request.source_branch,

marge/bot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _process_merge_requests(self, repo_manager, project, merge_requests):
146146
raise
147147

148148
log.info('Got %s requests to merge;', len(merge_requests))
149-
if self._config.batch and len(merge_requests) > 1:
149+
if (self._config.batch or self._config.optimistic_batch) and len(merge_requests) > 1:
150150
log.info('Attempting to merge as many MRs as possible using BatchMergeJob...')
151151
batch_merge_job = batch_job.BatchMergeJob(
152152
api=self._api,
@@ -155,6 +155,7 @@ def _process_merge_requests(self, repo_manager, project, merge_requests):
155155
merge_requests=merge_requests,
156156
repo=repo,
157157
options=self._config.merge_opts,
158+
optimistic=self._config.optimistic_batch,
158159
)
159160
try:
160161
batch_merge_job.execute()
@@ -187,7 +188,7 @@ def _get_single_job(self, project, merge_request, repo, options):
187188

188189
class BotConfig(namedtuple('BotConfig',
189190
'user ssh_key_file project_regexp merge_order merge_opts git_timeout ' +
190-
'git_reference_repo branch_regexp source_branch_regexp batch')):
191+
'git_reference_repo branch_regexp source_branch_regexp batch optimistic_batch')):
191192
pass
192193

193194

marge/git.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def remove_branch(self, branch, *, new_current_branch='master'):
131131
def checkout_branch(self, branch, start_point=''):
132132
self.git('checkout', '-B', branch, start_point, '--')
133133

134-
def push(self, branch, *, source_repo_url=None, force=False):
134+
def push(self, branch, *, source_repo_url=None, force=False, skip_ci=False):
135135
self.git('checkout', branch, '--')
136136

137137
self.git('diff-index', '--quiet', 'HEAD') # check it is not dirty
@@ -146,7 +146,8 @@ def push(self, branch, *, source_repo_url=None, force=False):
146146
else:
147147
source = 'origin'
148148
force_flag = '--force' if force else ''
149-
self.git('push', force_flag, source, '%s:%s' % (branch, branch))
149+
skip_flag = ['-o', 'ci.skip'] if skip_ci else []
150+
self.git('push', force_flag, *skip_flag, source, '%s:%s' % (branch, branch))
150151

151152
def get_commit_hash(self, rev='HEAD'):
152153
"""Return commit hash for `rev` (default "HEAD")."""

marge/job.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ def push_force_to_mr(
336336
merge_request,
337337
branch_was_modified,
338338
source_repo_url=None,
339+
skip_ci=False,
339340
):
340341
try:
341342
self._repo.push(
342343
merge_request.source_branch,
343344
source_repo_url=source_repo_url,
344345
force=True,
346+
skip_ci=skip_ci,
345347
)
346348
except git.GitError:
347349
def fetch_remote_branch():

pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ max-line-length=110
3030
[DESIGN]
3131
max-args=10
3232
max-attributes=15
33+
max-locals=16
3334
max-public-methods=35
3435

3536
[REPORTS]

tests/git_repo_mock.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ def merge(self, arg):
178178
self._local_repo.set_ref(self._branch, new_sha)
179179

180180
def push(self, *args):
181-
force_flag, remote_name, refspec = args
181+
force_flag, skip_1, skip_2, remote_name, refspec = args
182182

183183
assert force_flag in ('', '--force')
184+
assert skip_1 in ('', '-o')
185+
assert skip_2 in ('', 'ci.skip')
184186

185187
branch, remote_branch = refspec.split(':')
186188
remote_url = self._remotes[remote_name]

0 commit comments

Comments
 (0)