Skip to content

Commit 32569ea

Browse files
author
Gauvain Pocentek
committed
Implement commit.refs()
1 parent 63a4c7c commit 32569ea

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/gl_objects/commits.rst

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Cherry-pick a commit into another branch::
6565

6666
commit.cherry_pick(branch='target_branch')
6767

68+
Get the references the commit has been pushed to (branches and tags)::
69+
70+
commit.refs() # all references
71+
commit.refs('tag') # only tags
72+
commit.refs('branch') # only branches
73+
6874
Commit comments
6975
===============
7076

gitlab/v4/objects.py

+20
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,26 @@ def cherry_pick(self, branch, **kwargs):
12301230
post_data = {'branch': branch}
12311231
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
12321232

1233+
@cli.register_custom_action('ProjectCommit', optional=('type',))
1234+
@exc.on_http_error(exc.GitlabGetError)
1235+
def refs(self, type='all', **kwargs):
1236+
"""List the references the commit is pushed to.
1237+
1238+
Args:
1239+
type (str): The scope of references ('branch', 'tag' or 'all')
1240+
**kwargs: Extra options to send to the server (e.g. sudo)
1241+
1242+
Raises:
1243+
GitlabAuthenticationError: If authentication is not correct
1244+
GitlabGetError: If the references could not be retrieved
1245+
1246+
Returns:
1247+
list: The references the commit is pushed to.
1248+
"""
1249+
path = '%s/%s/refs' % (self.manager.path, self.get_id())
1250+
data = {'type': type}
1251+
return self.manager.gitlab.http_get(path, query_data=data, **kwargs)
1252+
12331253

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

tools/python_test_v4.py

+2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@
375375
status = commit.statuses.create({'state': 'success', 'sha': commit.id})
376376
assert(len(commit.statuses.list()) == 1)
377377

378+
assert(commit.refs())
379+
378380
# commit comment
379381
commit.comments.create({'note': 'This is a commit comment'})
380382
assert(len(commit.comments.list()) == 1)

0 commit comments

Comments
 (0)