From f4ee1286d2cfce6ed16db22a05d4d7d3e16d2317 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 12:45:24 +1000 Subject: [PATCH 1/6] Add support for fork listing from the fork manager --- gitlab/v4/objects.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 508ca7c4d..3f0158949 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'} @@ -1654,7 +1654,9 @@ class ProjectForkManager(CreateMixin, RESTManager): 'with_custom_attributes', 'with_issues_enabled', 'with_merge_requests_enabled') _create_attrs = (tuple(), ('namespace', )) - + + def list(self, **kwargs): + return super().list(path=self._compute_path(path=(self._path + "s")), **kwargs) class ProjectHook(SaveMixin, ObjectDeleteMixin, RESTObject): _short_print_attr = 'url' From effa504b31b57abad59498e9925d03bc52461ae1 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 13:08:15 +1000 Subject: [PATCH 2/6] Add basic documentation for fork.list() --- docs/gl_objects/projects.rst | 4 ++++ 1 file changed, 4 insertions(+) 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) From 43b45397745b00907cddd5e96c38f21f495dc011 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 13:13:07 +1000 Subject: [PATCH 3/6] Added test to check fork is in list --- tools/python_test_v4.py | 3 +++ 1 file changed, 3 insertions(+) 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) From da7c8db19a95ee716c6a78039fef38bb0dcb7300 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 13:30:46 +1000 Subject: [PATCH 4/6] Fixes to pass CI --- gitlab/v4/objects.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 3f0158949..c78dc3182 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1654,9 +1654,11 @@ class ProjectForkManager(CreateMixin, ListMixin, RESTManager): 'with_custom_attributes', 'with_issues_enabled', 'with_merge_requests_enabled') _create_attrs = (tuple(), ('namespace', )) - + def list(self, **kwargs): - return super().list(path=self._compute_path(path=(self._path + "s")), **kwargs) + computed_path = self._compute_path(path=(self._path + "s")) + return super(ProjectForkManager, self).list(path=computed_path, **kwargs) + class ProjectHook(SaveMixin, ObjectDeleteMixin, RESTObject): _short_print_attr = 'url' From f2dab106c6a2532f1285ce5e3eaaf28f49903e57 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 13:48:06 +1000 Subject: [PATCH 5/6] Used ListMixin instead of super like other overides added docsting --- gitlab/v4/objects.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index c78dc3182..d7b93dc39 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1656,8 +1656,26 @@ class ProjectForkManager(CreateMixin, ListMixin, RESTManager): _create_attrs = (tuple(), ('namespace', )) def list(self, **kwargs): - computed_path = self._compute_path(path=(self._path + "s")) - return super(ProjectForkManager, self).list(path=computed_path, **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): @@ -1813,7 +1831,7 @@ def move(self, to_project_id, **kwargs): path = '%s/%s/move' % (self.manager.path, self.get_id()) data = {'to_project_id': to_project_id} server_data = self.manager.gitlab.http_post(path, post_data=data, - **kwargs) +**kwargs) self._update_attrs(server_data) @cli.register_custom_action('ProjectIssue') From 4704c1d3e31b0fdfc595f82a0e95d8f48f3af8c8 Mon Sep 17 00:00:00 2001 From: David Guest Date: Wed, 25 Jul 2018 13:53:48 +1000 Subject: [PATCH 6/6] Reverting accidental change --- gitlab/v4/objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index d7b93dc39..743865531 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1831,7 +1831,7 @@ def move(self, to_project_id, **kwargs): path = '%s/%s/move' % (self.manager.path, self.get_id()) data = {'to_project_id': to_project_id} server_data = self.manager.gitlab.http_post(path, post_data=data, -**kwargs) + **kwargs) self._update_attrs(server_data) @cli.register_custom_action('ProjectIssue')