Skip to content

Commit 984d2ae

Browse files
committed
feat: Added approve method for Mergerequests
Offical GitLab API supports approval for GitLab EE
1 parent bdbec67 commit 984d2ae

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gitlab/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class GitlabMRForbiddenError(GitlabOperationError):
161161
pass
162162

163163

164+
class GitlabMRApprovalError(GitlabOperationError):
165+
pass
166+
164167
class GitlabMRClosedError(GitlabOperationError):
165168
pass
166169

gitlab/v4/objects.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,30 @@ 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,
2138+
sha,
2139+
**kwargs):
2140+
"""Approve the merge request.
2141+
2142+
Args:
2143+
sha (str): Head SHA of MR
2144+
**kwargs: Extra options to send to the server (e.g. sudo)
2145+
2146+
Raises:
2147+
GitlabAuthenticationError: If authentication is not correct
2148+
GitlabMRApprovalError: If the approval failed
2149+
"""
2150+
path = '%s/%s/approve' % (self.manager.path, self.get_id())
2151+
data = {}
2152+
if sha:
2153+
data['sha'] = sha
2154+
2155+
server_data = self.manager.gitlab.http_post(path, post_data=data,
2156+
**kwargs)
2157+
self._update_attrs(server_data)
2158+
21352159
@cli.register_custom_action('ProjectMergeRequest', tuple(),
21362160
('merge_commit_message',
21372161
'should_remove_source_branch',

0 commit comments

Comments
 (0)