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

Commit98c1307

Browse files
darkhaniopJohnVillalovos
authored andcommitted
feat(api): add listing user contributed projects
1 parent306c4b1 commit98c1307

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

‎docs/gl_objects/users.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ Get the followings of a user::
107107

108108
user.following_users.list(get_all=True)
109109

110+
List a user's contributed projects::
111+
112+
user.contributed_projects.list(get_all=True)
113+
110114
List a user's starred projects::
111115

112116
user.starred_projects.list(get_all=True)

‎gitlab/v4/objects/users.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
"UserMembershipManager",
6969
"UserProject",
7070
"UserProjectManager",
71+
"UserContributedProject",
72+
"UserContributedProjectManager",
7173
]
7274

7375

@@ -182,6 +184,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
182184
memberships:UserMembershipManager
183185
personal_access_tokens:UserPersonalAccessTokenManager
184186
projects:UserProjectManager
187+
contributed_projects:UserContributedProjectManager
185188
starred_projects:StarredProjectManager
186189
status:UserStatusManager
187190

@@ -665,6 +668,17 @@ def list(
665668
returnsuper().list(path=path,iterator=iterator,**kwargs)
666669

667670

671+
classUserContributedProject(RESTObject):
672+
_id_attr="id"
673+
_repr_attr="path_with_namespace"
674+
675+
676+
classUserContributedProjectManager(ListMixin[UserContributedProject]):
677+
_path="/users/{user_id}/contributed_projects"
678+
_obj_cls=UserContributedProject
679+
_from_parent_attrs= {"user_id":"id"}
680+
681+
668682
classStarredProject(RESTObject):
669683
pass
670684

‎tests/unit/objects/test_users.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
importpytest
88
importresponses
99

10-
fromgitlab.v4.objectsimportStarredProject,User,UserMembership,UserStatus
10+
fromgitlab.v4.objectsimport (
11+
StarredProject,
12+
User,
13+
UserContributedProject,
14+
UserMembership,
15+
UserStatus,
16+
)
1117

1218
from .test_projectsimportproject_content
1319

@@ -242,6 +248,19 @@ def resp_starred_projects():
242248
yieldrsps
243249

244250

251+
@pytest.fixture
252+
defresp_contributed_projects():
253+
withresponses.RequestsMock()asrsps:
254+
rsps.add(
255+
method=responses.GET,
256+
url="http://localhost/api/v4/users/1/contributed_projects",
257+
json=[project_content],
258+
content_type="application/json",
259+
status=200,
260+
)
261+
yieldrsps
262+
263+
245264
@pytest.fixture
246265
defresp_runner_create():
247266
withresponses.RequestsMock()asrsps:
@@ -314,6 +333,12 @@ def test_list_followers(user, resp_followers_following):
314333
assertfollowings[1].id==4
315334

316335

336+
deftest_list_contributed_projects(user,resp_contributed_projects):
337+
projects=user.contributed_projects.list()
338+
assertisinstance(projects[0],UserContributedProject)
339+
assertprojects[0].id==project_content["id"]
340+
341+
317342
deftest_list_starred_projects(user,resp_starred_projects):
318343
projects=user.starred_projects.list()
319344
assertisinstance(projects[0],StarredProject)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp