Skip to content

Commit 98c1307

Browse files
darkhaniopJohnVillalovos
authored andcommitted
feat(api): add listing user contributed projects
1 parent 306c4b1 commit 98c1307

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
return super().list(path=path, iterator=iterator, **kwargs)
666669

667670

671+
class UserContributedProject(RESTObject):
672+
_id_attr = "id"
673+
_repr_attr = "path_with_namespace"
674+
675+
676+
class UserContributedProjectManager(ListMixin[UserContributedProject]):
677+
_path = "/users/{user_id}/contributed_projects"
678+
_obj_cls = UserContributedProject
679+
_from_parent_attrs = {"user_id": "id"}
680+
681+
668682
class StarredProject(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
import pytest
88
import responses
99

10-
from gitlab.v4.objects import StarredProject, User, UserMembership, UserStatus
10+
from gitlab.v4.objects import (
11+
StarredProject,
12+
User,
13+
UserContributedProject,
14+
UserMembership,
15+
UserStatus,
16+
)
1117

1218
from .test_projects import project_content
1319

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

244250

251+
@pytest.fixture
252+
def resp_contributed_projects():
253+
with responses.RequestsMock() as rsps:
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+
yield rsps
262+
263+
245264
@pytest.fixture
246265
def resp_runner_create():
247266
with responses.RequestsMock() as rsps:
@@ -314,6 +333,12 @@ def test_list_followers(user, resp_followers_following):
314333
assert followings[1].id == 4
315334

316335

336+
def test_list_contributed_projects(user, resp_contributed_projects):
337+
projects = user.contributed_projects.list()
338+
assert isinstance(projects[0], UserContributedProject)
339+
assert projects[0].id == project_content["id"]
340+
341+
317342
def test_list_starred_projects(user, resp_starred_projects):
318343
projects = user.starred_projects.list()
319344
assert isinstance(projects[0], StarredProject)

0 commit comments

Comments
 (0)