diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst index 39508628f..fdee21597 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 508ca7c4d..743865531 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 3b5493692..79a78bc32 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -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)