Skip to content

Commit

Permalink
handle approve sudo error, and add marge as an approver
Browse files Browse the repository at this point in the history
  • Loading branch information
tclh123 committed Aug 12, 2020
1 parent 515406c commit d694b34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion marge/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ def reapprove(self):
"""
self.approve(self)

def approve(self, obj):
def approve(self, obj, add_marge=False):
"""Approve an object which can be a merge_request or an approval."""
if self._api.version().release >= (9, 2, 2):
approve_url = '/projects/{0.project_id}/merge_requests/{0.iid}/approve'.format(obj)
else:
# GitLab botched the v4 api before 9.2.3
approve_url = '/projects/{0.project_id}/merge_requests/{0.id}/approve'.format(obj)

if add_marge:
self._api.call(POST(approve_url))
for uid in self.approver_ids:
self._api.call(POST(approve_url), sudo=uid)
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, add_marge=True)
except gitlab.Forbidden:
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 d694b34

Please sign in to comment.