diff options
author | Max Wittig <max.wittig@siemens.com> | 2019-01-21 17:57:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-21 17:57:16 +0100 |
commit | 641b80a373746c9e6dc6d043216ebc4ba5613011 (patch) | |
tree | a4519d935a0b5ae5361cb178318402e09da17d75 /gitlab | |
parent | 52d76312660109d3669d459b11b448a3a60b9603 (diff) | |
parent | b51d2969ad34a9aad79e42a69f275caf2a4059cb (diff) | |
download | gitlab-641b80a373746c9e6dc6d043216ebc4ba5613011.tar.gz |
Merge pull request #685 from Joustie/master
feat: Added approve method for Mergerequests
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/exceptions.py | 4 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 41 |
2 files changed, 36 insertions, 9 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 0822d3e..5b7b75c 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -170,6 +170,10 @@ class GitlabMRForbiddenError(GitlabOperationError): pass +class GitlabMRApprovalError(GitlabOperationError): + pass + + class GitlabMRClosedError(GitlabOperationError): pass diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index c3714d8..af61488 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2277,23 +2277,46 @@ class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin, 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', |