Skip to content

Commit 641b80a

Browse files
authored
Merge pull request #685 from Joustie/master
feat: Added approve method for Mergerequests
2 parents 52d7631 + b51d296 commit 641b80a

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class GitlabMRForbiddenError(GitlabOperationError):
170170
pass
171171

172172

173+
class GitlabMRApprovalError(GitlabOperationError):
174+
pass
175+
176+
173177
class GitlabMRClosedError(GitlabOperationError):
174178
pass
175179

gitlab/v4/objects.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,23 +2277,46 @@ def changes(self, **kwargs):
22772277
path = '%s/%s/changes' % (self.manager.path, self.get_id())
22782278
return self.manager.gitlab.http_get(path, **kwargs)
22792279

2280-
@cli.register_custom_action('ProjectMergeRequest')
2281-
@exc.on_http_error(exc.GitlabListError)
2282-
def pipelines(self, **kwargs):
2283-
"""List the merge request pipelines.
2280+
@cli.register_custom_action('ProjectMergeRequest', tuple(), ('sha'))
2281+
@exc.on_http_error(exc.GitlabMRApprovalError)
2282+
def approve(self, sha=None, **kwargs):
2283+
"""Approve the merge request.
22842284
22852285
Args:
2286+
sha (str): Head SHA of MR
22862287
**kwargs: Extra options to send to the server (e.g. sudo)
22872288
22882289
Raises:
22892290
GitlabAuthenticationError: If authentication is not correct
2290-
GitlabListError: If the list could not be retrieved
2291+
GitlabMRApprovalError: If the approval failed
2292+
"""
2293+
path = '%s/%s/approve' % (self.manager.path, self.get_id())
2294+
data = {}
2295+
if sha:
2296+
data['sha'] = sha
22912297

2292-
Returns:
2293-
RESTObjectList: List of changes
2298+
server_data = self.manager.gitlab.http_post(path, post_data=data,
2299+
**kwargs)
2300+
self._update_attrs(server_data)
2301+
2302+
@cli.register_custom_action('ProjectMergeRequest')
2303+
@exc.on_http_error(exc.GitlabMRApprovalError)
2304+
def unapprove(self, **kwargs):
2305+
"""Unapprove the merge request.
2306+
2307+
Args:
2308+
**kwargs: Extra options to send to the server (e.g. sudo)
2309+
2310+
Raises:
2311+
GitlabAuthenticationError: If authentication is not correct
2312+
GitlabMRApprovalError: If the unapproval failed
22942313
"""
2295-
path = '%s/%s/pipelines' % (self.manager.path, self.get_id())
2296-
return self.manager.gitlab.http_get(path, **kwargs)
2314+
path = '%s/%s/unapprove' % (self.manager.path, self.get_id())
2315+
data = {}
2316+
2317+
server_data = self.manager.gitlab.http_post(path, post_data=data,
2318+
**kwargs)
2319+
self._update_attrs(server_data)
22972320

22982321
@cli.register_custom_action('ProjectMergeRequest', tuple(),
22992322
('merge_commit_message',

0 commit comments

Comments
 (0)