summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-01-21 11:42:12 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2018-01-21 11:42:12 +0100
commit96a1a784bd0cc0d0ce9dc3a83ea3a46380adc905 (patch)
treefd800cb6087d79069a7688ce4c41d51ec27ead3f
parent08f19b3d79dd50bab5afe58fe1b3b3825ddf9c25 (diff)
downloadgitlab-96a1a784bd0cc0d0ce9dc3a83ea3a46380adc905.tar.gz
Add support for getting list of user projects
Fixes #403
-rw-r--r--docs/gl_objects/projects.py1
-rw-r--r--gitlab/v4/objects.py27
-rw-r--r--tools/python_test_v4.py3
3 files changed, 30 insertions, 1 deletions
diff --git a/docs/gl_objects/projects.py b/docs/gl_objects/projects.py
index 7ec2359..425bbe2 100644
--- a/docs/gl_objects/projects.py
+++ b/docs/gl_objects/projects.py
@@ -33,6 +33,7 @@ project = gl.projects.create({'name': 'project1'})
# user create
alice = gl.users.list(username='alice')[0]
user_project = alice.projects.create({'name': 'project'})
+user_projects = alice.projects.list()
# end user create
# update
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 211527d..a5b603c 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -181,7 +181,7 @@ class UserProject(RESTObject):
pass
-class UserProjectManager(CreateMixin, RESTManager):
+class UserProjectManager(ListMixin, CreateMixin, RESTManager):
_path = '/projects/user/%(user_id)s'
_obj_cls = UserProject
_from_parent_attrs = {'user_id': 'id'}
@@ -192,6 +192,31 @@ class UserProjectManager(CreateMixin, RESTManager):
'public', 'visibility', 'description', 'builds_enabled',
'public_builds', 'import_url', 'only_allow_merge_if_build_succeeds')
)
+ _list_filters = ('archived', 'visibility', 'order_by', 'sort', 'search',
+ 'simple', 'owned', 'membership', 'starred', 'statistics',
+ 'with_issues_enabled', 'with_merge_requests_enabled')
+
+ 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 Gitlab 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 = '/users/%s/projects' % self._parent.id
+ return ListMixin.list(self, path=path, **kwargs)
class User(SaveMixin, ObjectDeleteMixin, RESTObject):
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 69596b8..e5d390a 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -92,6 +92,9 @@ assert(new_user.email == user.email)
new_user.block()
new_user.unblock()
+# user projects list
+assert(len(new_user.projects.list()) == 0)
+
foobar_user = gl.users.create(
{'email': 'foobar@example.com', 'username': 'foobar',
'name': 'Foo Bar', 'password': 'foobar_password'})