Skip to content

Commit

Permalink
fix: don't approve its own MR, and update the help message
Browse files Browse the repository at this point in the history
  • Loading branch information
tclh123 committed Aug 21, 2020
1 parent d694b34 commit 797990e
Show file tree
Hide file tree
Showing 3 changed files with 4 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. Please add sudo scope to the access token.\n',
)
parser.add_argument(
'--skip-ci-batches',
Expand Down
4 changes: 1 addition & 3 deletions marge/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ def reapprove(self):
"""
self.approve(self)

def approve(self, obj, add_marge=False):
def approve(self, obj):
"""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)
4 changes: 2 additions & 2 deletions marge/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ def execute(self):
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:
approvals.approve(batch_mr)
except (gitlab.Forbidden, gitlab.Unauthorized):
log.exception('Failed to approve MR:')

try:
Expand Down

0 comments on commit 797990e

Please sign in to comment.