Skip to content

Commit

Permalink
handle approving forbidden error, and update the help message
Browse files Browse the repository at this point in the history
  • Loading branch information
tclh123 committed Sep 8, 2020
1 parent 515406c commit 3876e49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def regexp(str_regex):
'--use-merge-commit-batches',
action='store_true',
help='Use merge commit when creating batches, so that the commits in the batch MR '
'will be the same with in individual MRs\n',
'will be the same with in individual MRs. Requires sudo scope in the access token.\n',
)
parser.add_argument(
'--skip-ci-batches',
Expand Down
14 changes: 9 additions & 5 deletions marge/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,16 @@ def execute(self):
merge_request.comment("I couldn't merge this branch: %s" % err.reason)
raise

# Approve the batch MR using the last sub MR's approvers
if not batch_mr.fetch_approvals().sufficient:
approvals = working_merge_requests[-1].fetch_approvals()
approvals.approve(batch_mr)
# Accept the batch MR
if self._options.use_merge_commit_batches:
# Approve the batch MR using the last sub MR's approvers
if not batch_mr.fetch_approvals().sufficient:
approvals = working_merge_requests[-1].fetch_approvals()
try:
approvals.approve(batch_mr)
except (gitlab.Forbidden, gitlab.Unauthorized):
log.exception('Failed to approve MR:')

try:
ret = batch_mr.accept(
remove_branch=batch_mr.force_remove_source_branch,
Expand All @@ -349,5 +353,5 @@ def execute(self):
)
log.info('batch_mr.accept result: %s', ret)
except gitlab.ApiError as err:
log.exception('Gitlab API Error: %s', err)
log.exception('Gitlab API Error:')
raise CannotMerge('Gitlab API Error: %s' % err)

0 comments on commit 3876e49

Please sign in to comment.