Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/gl_objects/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Fork a project::
# fork to a specific namespace
fork = project.forks.create({'namespace': 'myteam'})

Get a list of forks for the project::

forks = project.forks.list()

Create/delete a fork relation between projects (requires admin permissions)::

project.create_fork_relation(source_project.id)
Expand Down
24 changes: 23 additions & 1 deletion gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ class ProjectFork(RESTObject):
pass


class ProjectForkManager(CreateMixin, RESTManager):
class ProjectForkManager(CreateMixin, ListMixin, RESTManager):
_path = '/projects/%(project_id)s/fork'
_obj_cls = ProjectFork
_from_parent_attrs = {'project_id': 'id'}
Expand All @@ -1655,6 +1655,28 @@ class ProjectForkManager(CreateMixin, RESTManager):
'with_merge_requests_enabled')
_create_attrs = (tuple(), ('namespace', ))

def list(self, **kwargs):
"""Retrieve a list of objects.

Args:
all (bool): If True, return all the items, without pagination
per_page (int): Number of items to retrieve per request
page (int): ID of the page to return (starts with page 1)
as_list (bool): If set to False and no pagination option is
defined, return a generator instead of a list
**kwargs: Extra options to send to the server (e.g. sudo)

Returns:
list: The list of objects, or a generator if `as_list` is False

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabListError: If the server cannot perform the request
"""

path = self._compute_path('/projects/%(project_id)s/forks')
return ListMixin.list(self, path=path, **kwargs)


class ProjectHook(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'url'
Expand Down
3 changes: 3 additions & 0 deletions tools/python_test_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@
p = gl.projects.get(fork.id)
assert(p.forked_from_project['id'] == admin_project.id)

forks = admin_project.forks.list()
assert(fork.id in map(lambda p: p.id, forks))

# project hooks
hook = admin_project.hooks.create({'url': 'http://hook.url'})
assert(len(admin_project.hooks.list()) == 1)
Expand Down