Skip to content

Commit b325bd7

Browse files
owmtiaGauvain Pocentek
authored andcommitted
Added support for listing forks of a project (#562)
1 parent 35c8c82 commit b325bd7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/gl_objects/projects.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ Fork a project::
9595
# fork to a specific namespace
9696
fork = project.forks.create({'namespace': 'myteam'})
9797

98+
Get a list of forks for the project::
99+
100+
forks = project.forks.list()
101+
98102
Create/delete a fork relation between projects (requires admin permissions)::
99103

100104
project.create_fork_relation(source_project.id)

gitlab/v4/objects.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ class ProjectFork(RESTObject):
16451645
pass
16461646

16471647

1648-
class ProjectForkManager(CreateMixin, RESTManager):
1648+
class ProjectForkManager(CreateMixin, ListMixin, RESTManager):
16491649
_path = '/projects/%(project_id)s/fork'
16501650
_obj_cls = ProjectFork
16511651
_from_parent_attrs = {'project_id': 'id'}
@@ -1655,6 +1655,28 @@ class ProjectForkManager(CreateMixin, RESTManager):
16551655
'with_merge_requests_enabled')
16561656
_create_attrs = (tuple(), ('namespace', ))
16571657

1658+
def list(self, **kwargs):
1659+
"""Retrieve a list of objects.
1660+
1661+
Args:
1662+
all (bool): If True, return all the items, without pagination
1663+
per_page (int): Number of items to retrieve per request
1664+
page (int): ID of the page to return (starts with page 1)
1665+
as_list (bool): If set to False and no pagination option is
1666+
defined, return a generator instead of a list
1667+
**kwargs: Extra options to send to the server (e.g. sudo)
1668+
1669+
Returns:
1670+
list: The list of objects, or a generator if `as_list` is False
1671+
1672+
Raises:
1673+
GitlabAuthenticationError: If authentication is not correct
1674+
GitlabListError: If the server cannot perform the request
1675+
"""
1676+
1677+
path = self._compute_path('/projects/%(project_id)s/forks')
1678+
return ListMixin.list(self, path=path, **kwargs)
1679+
16581680

16591681
class ProjectHook(SaveMixin, ObjectDeleteMixin, RESTObject):
16601682
_short_print_attr = 'url'

tools/python_test_v4.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@
467467
p = gl.projects.get(fork.id)
468468
assert(p.forked_from_project['id'] == admin_project.id)
469469

470+
forks = admin_project.forks.list()
471+
assert(fork.id in map(lambda p: p.id, forks))
472+
470473
# project hooks
471474
hook = admin_project.hooks.create({'url': 'http://hook.url'})
472475
assert(len(admin_project.hooks.list()) == 1)

0 commit comments

Comments
 (0)