Skip to content

Commit 53f7de7

Browse files
committed
feat: Added approve & unapprove method for Mergerequests
Offical GitLab API supports this for GitLab EE
1 parent bdbec67 commit 53f7de7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

gitlab/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ class GitlabMRForbiddenError(GitlabOperationError):
161161
pass
162162

163163

164+
class GitlabMRApprovalError(GitlabOperationError):
165+
pass
166+
167+
164168
class GitlabMRClosedError(GitlabOperationError):
165169
pass
166170

gitlab/v4/objects.py

+41
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,47 @@ def changes(self, **kwargs):
21322132
path = '%s/%s/changes' % (self.manager.path, self.get_id())
21332133
return self.manager.gitlab.http_get(path, **kwargs)
21342134

2135+
@cli.register_custom_action('ProjectMergeRequest', tuple(), ('sha'))
2136+
@exc.on_http_error(exc.GitlabMRApprovalError)
2137+
def approve(self, sha=None, **kwargs):
2138+
"""Approve the merge request.
2139+
2140+
Args:
2141+
sha (str): Head SHA of MR
2142+
**kwargs: Extra options to send to the server (e.g. sudo)
2143+
2144+
Raises:
2145+
GitlabAuthenticationError: If authentication is not correct
2146+
GitlabMRApprovalError: If the approval failed
2147+
"""
2148+
path = '%s/%s/approve' % (self.manager.path, self.get_id())
2149+
data = {}
2150+
if sha:
2151+
data['sha'] = sha
2152+
2153+
server_data = self.manager.gitlab.http_post(path, post_data=data,
2154+
**kwargs)
2155+
self._update_attrs(server_data)
2156+
2157+
@cli.register_custom_action('ProjectMergeRequest')
2158+
@exc.on_http_error(exc.GitlabMRApprovalError)
2159+
def unapprove(self, **kwargs):
2160+
"""Unapprove the merge request.
2161+
2162+
Args:
2163+
**kwargs: Extra options to send to the server (e.g. sudo)
2164+
2165+
Raises:
2166+
GitlabAuthenticationError: If authentication is not correct
2167+
GitlabMRApprovalError: If the unapproval failed
2168+
"""
2169+
path = '%s/%s/unapprove' % (self.manager.path, self.get_id())
2170+
data = {}
2171+
2172+
server_data = self.manager.gitlab.http_post(path, post_data=data,
2173+
**kwargs)
2174+
self._update_attrs(server_data)
2175+
21352176
@cli.register_custom_action('ProjectMergeRequest', tuple(),
21362177
('merge_commit_message',
21372178
'should_remove_source_branch',

0 commit comments

Comments
 (0)