summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Guest <owmtia@gmail.com>2018-07-26 15:18:38 +1000
committerGauvain Pocentek <gauvain@pocentek.net>2018-07-26 07:18:38 +0200
commitb325bd73400e3806e6ede59cc10011fbf138b877 (patch)
tree82cc2d5dba5954df5dedfe9bdbc53c2c47ad6eaa
parent35c8c8298392188c51e5956dd2eb90bb3d81a301 (diff)
downloadgitlab-b325bd73400e3806e6ede59cc10011fbf138b877.tar.gz
Added support for listing forks of a project (#562)
-rw-r--r--docs/gl_objects/projects.rst4
-rw-r--r--gitlab/v4/objects.py24
-rw-r--r--tools/python_test_v4.py3
3 files changed, 30 insertions, 1 deletions
diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst
index 3950862..fdee215 100644
--- a/docs/gl_objects/projects.rst
+++ b/docs/gl_objects/projects.rst
@@ -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)
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 508ca7c..7438655 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -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'}
@@ -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'
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 3b54936..79a78bc 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -467,6 +467,9 @@ fork = admin_project.forks.create({'namespace': user1.username})
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)