Skip to content

Commit c19ad90

Browse files
author
Gauvain Pocentek
committed
Add commit.merge_requests() support
1 parent 3c53f7f commit c19ad90

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

docs/gl_objects/commits.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Get the references the commit has been pushed to (branches and tags)::
7171
commit.refs('tag') # only tags
7272
commit.refs('branch') # only branches
7373

74+
List the merge requests related to a commit::
75+
76+
commit.merge_requests()
77+
7478
Commit comments
7579
===============
7680

gitlab/v4/objects.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,24 @@ def refs(self, type='all', **kwargs):
12501250
data = {'type': type}
12511251
return self.manager.gitlab.http_get(path, query_data=data, **kwargs)
12521252

1253+
@cli.register_custom_action('ProjectCommit')
1254+
@exc.on_http_error(exc.GitlabGetError)
1255+
def merge_requests(self, **kwargs):
1256+
"""List the merge requests related to the commit.
1257+
1258+
Args:
1259+
**kwargs: Extra options to send to the server (e.g. sudo)
1260+
1261+
Raises:
1262+
GitlabAuthenticationError: If authentication is not correct
1263+
GitlabGetError: If the references could not be retrieved
1264+
1265+
Returns:
1266+
list: The merge requests related to the commit.
1267+
"""
1268+
path = '%s/%s/merge_requests' % (self.manager.path, self.get_id())
1269+
return self.manager.gitlab.http_get(path, **kwargs)
1270+
12531271

12541272
class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
12551273
_path = '/projects/%(project_id)s/repository/commits'

tools/python_test_v4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
assert(len(commit.statuses.list()) == 1)
377377

378378
assert(commit.refs())
379+
assert(commit.merge_requests() is not None)
379380

380381
# commit comment
381382
commit.comments.create({'note': 'This is a commit comment'})

0 commit comments

Comments
 (0)