Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d1a3ac

Browse files
committed
feat: Added approve & unapprove method for Mergerequests
Offical GitLab API supports this for GitLab EE
1 parentbdbec67 commit2d1a3ac

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎gitlab/exceptions.py

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

163163

164+
classGitlabMRApprovalError(GitlabOperationError):
165+
pass
166+
167+
164168
classGitlabMRClosedError(GitlabOperationError):
165169
pass
166170

‎gitlab/v4/objects.py

Lines changed: 41 additions & 0 deletions
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
returnself.manager.gitlab.http_get(path,**kwargs)
21342134

2135+
@cli.register_custom_action('ProjectMergeRequest',tuple(), ('sha'))
2136+
@exc.on_http_error(exc.GitlabMRApprovalError)
2137+
defapprove(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+
ifsha:
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+
defunapprove(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)

[8]ページ先頭

©2009-2025 Movatter.jp