Skip to content

Commit

Permalink
Add commit.merge_requests() support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed May 28, 2018
1 parent 3c53f7f commit c19ad90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/gl_objects/commits.rst
Expand Up @@ -71,6 +71,10 @@ Get the references the commit has been pushed to (branches and tags)::
commit.refs('tag') # only tags
commit.refs('branch') # only branches

List the merge requests related to a commit::

commit.merge_requests()

Commit comments
===============

Expand Down
18 changes: 18 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -1250,6 +1250,24 @@ def refs(self, type='all', **kwargs):
data = {'type': type}
return self.manager.gitlab.http_get(path, query_data=data, **kwargs)

@cli.register_custom_action('ProjectCommit')
@exc.on_http_error(exc.GitlabGetError)
def merge_requests(self, **kwargs):
"""List the merge requests related to the commit.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the references could not be retrieved
Returns:
list: The merge requests related to the commit.
"""
path = '%s/%s/merge_requests' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)


class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
_path = '/projects/%(project_id)s/repository/commits'
Expand Down
1 change: 1 addition & 0 deletions tools/python_test_v4.py
Expand Up @@ -376,6 +376,7 @@
assert(len(commit.statuses.list()) == 1)

assert(commit.refs())
assert(commit.merge_requests() is not None)

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

0 comments on commit c19ad90

Please sign in to comment.