Skip to content

Commit

Permalink
Add support for getting list of user projects
Browse files Browse the repository at this point in the history
Fixes #403
  • Loading branch information
Gauvain Pocentek committed Jan 21, 2018
1 parent 08f19b3 commit 96a1a78
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/gl_objects/projects.py
Expand Up @@ -33,6 +33,7 @@
# 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
Expand Down
27 changes: 26 additions & 1 deletion gitlab/v4/objects.py
Expand Up @@ -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'}
Expand All @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tools/python_test_v4.py
Expand Up @@ -92,6 +92,9 @@
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'})
Expand Down

0 comments on commit 96a1a78

Please sign in to comment.