summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-05-28 07:14:58 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2018-05-28 07:14:58 +0200
commit32569ea27d36c7341b031f11d14f79fd6abd373f (patch)
treec9e1b8e0b4f8430bfa0fbe0fffcbbd35d7376468
parent63a4c7c95112f6c6aed6e9fa6cf4afd88f0b80e7 (diff)
downloadgitlab-32569ea27d36c7341b031f11d14f79fd6abd373f.tar.gz
Implement commit.refs()
-rw-r--r--docs/gl_objects/commits.rst6
-rw-r--r--gitlab/v4/objects.py20
-rw-r--r--tools/python_test_v4.py2
3 files changed, 28 insertions, 0 deletions
diff --git a/docs/gl_objects/commits.rst b/docs/gl_objects/commits.rst
index 22e23f6..d04d731 100644
--- a/docs/gl_objects/commits.rst
+++ b/docs/gl_objects/commits.rst
@@ -65,6 +65,12 @@ Cherry-pick a commit into another branch::
commit.cherry_pick(branch='target_branch')
+Get the references the commit has been pushed to (branches and tags)::
+
+ commit.refs() # all references
+ commit.refs('tag') # only tags
+ commit.refs('branch') # only branches
+
Commit comments
===============
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 46a6fd7..f18ffdd 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -1230,6 +1230,26 @@ class ProjectCommit(RESTObject):
post_data = {'branch': branch}
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
+ @cli.register_custom_action('ProjectCommit', optional=('type',))
+ @exc.on_http_error(exc.GitlabGetError)
+ def refs(self, type='all', **kwargs):
+ """List the references the commit is pushed to.
+
+ Args:
+ type (str): The scope of references ('branch', 'tag' or 'all')
+ **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 references the commit is pushed to.
+ """
+ path = '%s/%s/refs' % (self.manager.path, self.get_id())
+ data = {'type': type}
+ return self.manager.gitlab.http_get(path, query_data=data, **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 fc19ee7..f9ea102 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -375,6 +375,8 @@ commit = admin_project.commits.list()[0]
status = commit.statuses.create({'state': 'success', 'sha': commit.id})
assert(len(commit.statuses.list()) == 1)
+assert(commit.refs())
+
# commit comment
commit.comments.create({'note': 'This is a commit comment'})
assert(len(commit.comments.list()) == 1)