| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 79785f0 commit 47a5606
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,11 @@ Results can also be sorted using the following parameters: | |||
| 55 | 55 | # Search projects | |
| 56 | 56 | projects = gl.projects.list(search='keyword') | |
| 57 | 57 | ||
| 58 | + .. note:: | ||
| 59 | + | ||
| 60 | + To list the starred projects of another user, see the | ||
| 61 | + :ref:`Users API docs <users_examples>`. | ||
| 62 | + | ||
| 58 | 63 | .. note:: | |
| 59 | 64 | ||
| 60 | 65 | Fetching a list of projects, doesn't include all attributes of all projects. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + .. _users_examples: | ||
| 2 | + | ||
| 1 | 3 | ###################### | |
| 2 | 4 | Users and current user | |
| 3 | 5 | ###################### | |
@@ -19,7 +21,10 @@ References | |||
| 19 | 21 | + :class:`gitlab.v4.objects.UserManager` | |
| 20 | 22 | + :attr:`gitlab.Gitlab.users` | |
| 21 | 23 | ||
| 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 | ||
| 23 | 28 | ||
| 24 | 29 | Examples | |
| 25 | 30 | -------- | |
@@ -97,6 +102,9 @@ Get the followings of a user | |||
| 97 | 102 | ||
| 98 | 103 | user.following_users.list() | |
| 99 | 104 | ||
| 105 | + List a user's starred projects | ||
| 106 | + | ||
| 107 | + user.starred_projects.list() | ||
| 100 | 108 | ||
| 101 | 109 | User custom attributes | |
| 102 | 110 | ====================== | |
| Original file line number | Diff line number | Diff 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 | + """ | ||
| 1 | 6 | from typing import Any, cast, Dict, List, Union | |
| 2 | 7 | ||
| 3 | 8 | import requests | |
@@ -38,6 +43,8 @@ | |||
| 38 | 43 | "UserManager", | |
| 39 | 44 | "ProjectUser", | |
| 40 | 45 | "ProjectUserManager", | |
| 46 | + "StarredProject", | ||
| 47 | + "StarredProjectManager", | ||
| 41 | 48 | "UserEmail", | |
| 42 | 49 | "UserEmailManager", | |
| 43 | 50 | "UserActivities", | |
@@ -129,6 +136,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 129 | 136 | memberships: "UserMembershipManager" | |
| 130 | 137 | personal_access_tokens: UserPersonalAccessTokenManager | |
| 131 | 138 | projects: "UserProjectManager" | |
| 139 | + starred_projects: "StarredProjectManager" | ||
| 132 | 140 | status: "UserStatusManager" | |
| 133 | 141 | ||
| 134 | 142 | @cli.register_custom_action("User") | |
@@ -502,6 +510,32 @@ def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | |||
| 502 | 510 | return ListMixin.list(self, path=path, **kwargs) | |
| 503 | 511 | ||
| 504 | 512 | ||
| 513 | + class StarredProject(RESTObject): | ||
| 514 | + pass | ||
| 515 | + | ||
| 516 | + | ||
| 517 | + class StarredProjectManager(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 | + | ||
| 505 | 539 | class UserFollowersManager(ListMixin, RESTManager): | |
| 506 | 540 | _path = "/users/%(user_id)s/followers" | |
| 507 | 541 | _obj_cls = User | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,14 @@ | |||
| 1 | 1 | """ | |
| 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 | ||
| 3 | 5 | """ | |
| 4 | 6 | import pytest | |
| 5 | 7 | import responses | |
| 6 | 8 | ||
| 7 | - from gitlab.v4.objects import User, UserMembership, UserStatus | ||
| 9 | + from gitlab.v4.objects import StarredProject, User, UserMembership, UserStatus | ||
| 10 | + | ||
| 11 | + from .test_projects import project_content | ||
| 8 | 12 | ||
| 9 | 13 | ||
| 10 | 14 | @pytest.fixture | |
@@ -174,6 +178,19 @@ def resp_followers_following(): | |||
| 174 | 178 | yield rsps | |
| 175 | 179 | ||
| 176 | 180 | ||
| 181 | + @pytest.fixture | ||
| 182 | + def resp_starred_projects(): | ||
| 183 | + with responses.RequestsMock() as rsps: | ||
| 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 | + yield rsps | ||
| 192 | + | ||
| 193 | + | ||
| 177 | 194 | def test_get_user(gl, resp_get_user): | |
| 178 | 195 | user = gl.users.get(1) | |
| 179 | 196 | assert isinstance(user, User) | |
@@ -215,3 +232,9 @@ def test_list_followers(user, resp_followers_following): | |||
| 215 | 232 | assert followers[0].id == 2 | |
| 216 | 233 | assert isinstance(followings[0], User) | |
| 217 | 234 | assert followings[1].id == 4 | |
| 235 | + | ||
| 236 | + | ||
| 237 | + def test_list_starred_projects(user, resp_starred_projects): | ||
| 238 | + projects = user.starred_projects.list() | ||
| 239 | + assert isinstance(projects[0], StarredProject) | ||
| 240 | + assert projects[0].id == project_content["id"] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments