summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/gl_objects/commits.rst4
-rw-r--r--gitlab/v4/objects.py18
-rw-r--r--tools/python_test_v4.py1
3 files changed, 23 insertions, 0 deletions
diff --git a/docs/gl_objects/commits.rst b/docs/gl_objects/commits.rst
index d04d731..f662fcb 100644
--- a/docs/gl_objects/commits.rst
+++ b/docs/gl_objects/commits.rst
@@ -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
===============
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index f18ffdd..df565af 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -1250,6 +1250,24 @@ class ProjectCommit(RESTObject):
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'
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 26e0488..0551093 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -376,6 +376,7 @@ status = commit.statuses.create({'state': 'success', 'sha': commit.id})
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'})