Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit47a5606

Browse files
nejchJohnVillalovos
authored andcommitted
feat(objects): list starred projects of a user
1 parent79785f0 commit47a5606

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

‎docs/gl_objects/projects.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Results can also be sorted using the following parameters:
5555
# Search projects
5656
projects = gl.projects.list(search='keyword')
5757

58+
..note::
59+
60+
To list the starred projects of another user, see the
61+
:ref:`Users API docs<users_examples>`.
62+
5863
..note::
5964

6065
Fetching a list of projects, doesn't include all attributes of all projects.

‎docs/gl_objects/users.rst‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _users_examples:
2+
13
######################
24
Users and current user
35
######################
@@ -19,7 +21,10 @@ References
1921
+:class:`gitlab.v4.objects.UserManager`
2022
+:attr:`gitlab.Gitlab.users`
2123

22-
* GitLab API: https://docs.gitlab.com/ce/api/users.html
24+
* GitLab API:
25+
26+
+ https://docs.gitlab.com/ce/api/users.html
27+
+ https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
2328

2429
Examples
2530
--------
@@ -97,6 +102,9 @@ Get the followings of a user
97102

98103
user.following_users.list()
99104

105+
List a user's starred projects
106+
107+
user.starred_projects.list()
100108

101109
User custom attributes
102110
======================

‎gitlab/v4/objects/users.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ee/api/users.html
4+
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
5+
"""
16
fromtypingimportAny,cast,Dict,List,Union
27

38
importrequests
@@ -38,6 +43,8 @@
3843
"UserManager",
3944
"ProjectUser",
4045
"ProjectUserManager",
46+
"StarredProject",
47+
"StarredProjectManager",
4148
"UserEmail",
4249
"UserEmailManager",
4350
"UserActivities",
@@ -129,6 +136,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
129136
memberships:"UserMembershipManager"
130137
personal_access_tokens:UserPersonalAccessTokenManager
131138
projects:"UserProjectManager"
139+
starred_projects:"StarredProjectManager"
132140
status:"UserStatusManager"
133141

134142
@cli.register_custom_action("User")
@@ -502,6 +510,32 @@ def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]:
502510
returnListMixin.list(self,path=path,**kwargs)
503511

504512

513+
classStarredProject(RESTObject):
514+
pass
515+
516+
517+
classStarredProjectManager(ListMixin,RESTManager):
518+
_path="/users/%(user_id)s/starred_projects"
519+
_obj_cls=StarredProject
520+
_from_parent_attrs= {"user_id":"id"}
521+
_list_filters= (
522+
"archived",
523+
"membership",
524+
"min_access_level",
525+
"order_by",
526+
"owned",
527+
"search",
528+
"simple",
529+
"sort",
530+
"starred",
531+
"statistics",
532+
"visibility",
533+
"with_custom_attributes",
534+
"with_issues_enabled",
535+
"with_merge_requests_enabled",
536+
)
537+
538+
505539
classUserFollowersManager(ListMixin,RESTManager):
506540
_path="/users/%(user_id)s/followers"
507541
_obj_cls=User

‎tests/unit/objects/test_users.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""
2-
GitLab API: https://docs.gitlab.com/ce/api/users.html
2+
GitLab API:
3+
https://docs.gitlab.com/ce/api/users.html
4+
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
35
"""
46
importpytest
57
importresponses
68

7-
fromgitlab.v4.objectsimportUser,UserMembership,UserStatus
9+
fromgitlab.v4.objectsimportStarredProject,User,UserMembership,UserStatus
10+
11+
from .test_projectsimportproject_content
812

913

1014
@pytest.fixture
@@ -174,6 +178,19 @@ def resp_followers_following():
174178
yieldrsps
175179

176180

181+
@pytest.fixture
182+
defresp_starred_projects():
183+
withresponses.RequestsMock()asrsps:
184+
rsps.add(
185+
method=responses.GET,
186+
url="http://localhost/api/v4/users/1/starred_projects",
187+
json=[project_content],
188+
content_type="application/json",
189+
status=200,
190+
)
191+
yieldrsps
192+
193+
177194
deftest_get_user(gl,resp_get_user):
178195
user=gl.users.get(1)
179196
assertisinstance(user,User)
@@ -215,3 +232,9 @@ def test_list_followers(user, resp_followers_following):
215232
assertfollowers[0].id==2
216233
assertisinstance(followings[0],User)
217234
assertfollowings[1].id==4
235+
236+
237+
deftest_list_starred_projects(user,resp_starred_projects):
238+
projects=user.starred_projects.list()
239+
assertisinstance(projects[0],StarredProject)
240+
assertprojects[0].id==project_content["id"]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp