Skip to content

Commit

Permalink
Merge pull request #685 from Joustie/master
Browse files Browse the repository at this point in the history
feat: Added approve method for Mergerequests
  • Loading branch information
max-wittig committed Jan 21, 2019
2 parents 52d7631 + b51d296 commit 641b80a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Expand Up @@ -170,6 +170,10 @@ class GitlabMRForbiddenError(GitlabOperationError):
pass


class GitlabMRApprovalError(GitlabOperationError):
pass


class GitlabMRClosedError(GitlabOperationError):
pass

Expand Down
41 changes: 32 additions & 9 deletions gitlab/v4/objects.py
Expand Up @@ -2277,23 +2277,46 @@ def changes(self, **kwargs):
path = '%s/%s/changes' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)

@cli.register_custom_action('ProjectMergeRequest')
@exc.on_http_error(exc.GitlabListError)
def pipelines(self, **kwargs):
"""List the merge request pipelines.
@cli.register_custom_action('ProjectMergeRequest', tuple(), ('sha'))
@exc.on_http_error(exc.GitlabMRApprovalError)
def approve(self, sha=None, **kwargs):
"""Approve the merge request.
Args:
sha (str): Head SHA of MR
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabListError: If the list could not be retrieved
GitlabMRApprovalError: If the approval failed
"""
path = '%s/%s/approve' % (self.manager.path, self.get_id())
data = {}
if sha:
data['sha'] = sha

Returns:
RESTObjectList: List of changes
server_data = self.manager.gitlab.http_post(path, post_data=data,
**kwargs)
self._update_attrs(server_data)

@cli.register_custom_action('ProjectMergeRequest')
@exc.on_http_error(exc.GitlabMRApprovalError)
def unapprove(self, **kwargs):
"""Unapprove the merge request.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabMRApprovalError: If the unapproval failed
"""
path = '%s/%s/pipelines' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)
path = '%s/%s/unapprove' % (self.manager.path, self.get_id())
data = {}

server_data = self.manager.gitlab.http_post(path, post_data=data,
**kwargs)
self._update_attrs(server_data)

@cli.register_custom_action('ProjectMergeRequest', tuple(),
('merge_commit_message',
Expand Down

0 comments on commit 641b80a

Please sign in to comment.