Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96a1a78

Browse filesBrowse files
author
Gauvain Pocentek
committed
Add support for getting list of user projects
Fixes python-gitlab#403
1 parent 08f19b3 commit 96a1a78
Copy full SHA for 96a1a78

File tree

Expand file treeCollapse file tree

3 files changed

+30
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-1
lines changed
Open diff view settings
Collapse file

‎docs/gl_objects/projects.py‎

Copy file name to clipboardExpand all lines: docs/gl_objects/projects.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# user create
3434
alice = gl.users.list(username='alice')[0]
3535
user_project = alice.projects.create({'name': 'project'})
36+
user_projects = alice.projects.list()
3637
# end user create
3738

3839
# update
Collapse file

‎gitlab/v4/objects.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects.py
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class UserProject(RESTObject):
181181
pass
182182

183183

184-
class UserProjectManager(CreateMixin, RESTManager):
184+
class UserProjectManager(ListMixin, CreateMixin, RESTManager):
185185
_path = '/projects/user/%(user_id)s'
186186
_obj_cls = UserProject
187187
_from_parent_attrs = {'user_id': 'id'}
@@ -192,6 +192,31 @@ class UserProjectManager(CreateMixin, RESTManager):
192192
'public', 'visibility', 'description', 'builds_enabled',
193193
'public_builds', 'import_url', 'only_allow_merge_if_build_succeeds')
194194
)
195+
_list_filters = ('archived', 'visibility', 'order_by', 'sort', 'search',
196+
'simple', 'owned', 'membership', 'starred', 'statistics',
197+
'with_issues_enabled', 'with_merge_requests_enabled')
198+
199+
def list(self, **kwargs):
200+
"""Retrieve a list of objects.
201+
202+
Args:
203+
all (bool): If True, return all the items, without pagination
204+
per_page (int): Number of items to retrieve per request
205+
page (int): ID of the page to return (starts with page 1)
206+
as_list (bool): If set to False and no pagination option is
207+
defined, return a generator instead of a list
208+
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
209+
210+
Returns:
211+
list: The list of objects, or a generator if `as_list` is False
212+
213+
Raises:
214+
GitlabAuthenticationError: If authentication is not correct
215+
GitlabListError: If the server cannot perform the request
216+
"""
217+
218+
path = '/users/%s/projects' % self._parent.id
219+
return ListMixin.list(self, path=path, **kwargs)
195220

196221

197222
class User(SaveMixin, ObjectDeleteMixin, RESTObject):
Collapse file

‎tools/python_test_v4.py‎

Copy file name to clipboardExpand all lines: tools/python_test_v4.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
new_user.block()
9393
new_user.unblock()
9494

95+
# user projects list
96+
assert(len(new_user.projects.list()) == 0)
97+
9598
foobar_user = gl.users.create(
9699
{'email': 'foobar@example.com', 'username': 'foobar',
97100
'name': 'Foo Bar', 'password': 'foobar_password'})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.