gitcode-api 1.2.20__py3-none-any.whl → 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. gitcode_api/__init__.py +8 -2
  2. gitcode_api/_base_client.py +7 -2
  3. gitcode_api/_exceptions.py +8 -0
  4. gitcode_api/exceptions.py +19 -0
  5. gitcode_api/llm/mcp.py +5 -5
  6. gitcode_api/models.py +205 -0
  7. gitcode_api/resources/__init__.py +1 -1
  8. gitcode_api/resources/_shared/__init__.py +18 -0
  9. gitcode_api/resources/_shared/base.py +129 -0
  10. gitcode_api/resources/{_shared.py → _shared/fetch_template.py} +133 -259
  11. gitcode_api/resources/account/__init__.py +17 -0
  12. gitcode_api/resources/account/oauth_resource_group.py +159 -0
  13. gitcode_api/resources/account/orgs_resource_group.py +422 -0
  14. gitcode_api/resources/account/search_resource_group.py +236 -0
  15. gitcode_api/resources/account/users_resource_group.py +249 -0
  16. gitcode_api/resources/collaboration/__init__.py +20 -0
  17. gitcode_api/resources/collaboration/_helpers.py +10 -0
  18. gitcode_api/resources/collaboration/issues_resource_group.py +855 -0
  19. gitcode_api/resources/collaboration/labels_resource_group.py +248 -0
  20. gitcode_api/resources/collaboration/members_resource_group.py +195 -0
  21. gitcode_api/resources/collaboration/milestones_resource_group.py +192 -0
  22. gitcode_api/resources/collaboration/pulls_resource_group.py +1300 -0
  23. gitcode_api/resources/misc/__init__.py +14 -0
  24. gitcode_api/resources/misc/releases_resource_group.py +445 -0
  25. gitcode_api/resources/misc/tags_resource_group.py +286 -0
  26. gitcode_api/resources/misc/webhooks_resource_group.py +192 -0
  27. gitcode_api/resources/repositories/__init__.py +17 -0
  28. gitcode_api/resources/repositories/branches_resource_group.py +151 -0
  29. gitcode_api/resources/repositories/commits_resource_group.py +333 -0
  30. gitcode_api/resources/repositories/repo_contents_resource_group.py +459 -0
  31. gitcode_api/resources/repositories/repos_resource_group.py +1279 -0
  32. gitcode_api/version.txt +1 -1
  33. {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/METADATA +3 -3
  34. gitcode_api-1.3.0.dist-info/RECORD +52 -0
  35. gitcode_api/resources/account.py +0 -1086
  36. gitcode_api/resources/collaboration.py +0 -2818
  37. gitcode_api/resources/misc.py +0 -901
  38. gitcode_api/resources/repositories.py +0 -2197
  39. gitcode_api-1.2.20.dist-info/RECORD +0 -31
  40. {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/WHEEL +0 -0
  41. {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/entry_points.txt +0 -0
  42. {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/licenses/LICENSE +0 -0
  43. {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,249 @@
1
+ """AbstractUsersResource, UsersResource, and AsyncUsersResource resource group."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import List, Optional, Union
5
+
6
+ from ..._models import (
7
+ APIObject,
8
+ Email,
9
+ Namespace,
10
+ PublicKey,
11
+ Repository,
12
+ User,
13
+ UserEventsResponse,
14
+ )
15
+ from .._shared import AsyncResource, SyncResource
16
+
17
+ # mypy: disable-error-code=override
18
+ # pylint: disable=invalid-overridden-method,protected-access,redefined-builtin
19
+
20
+
21
+ class AbstractUsersResource(ABC):
22
+ """Interface for Users resource endpoints."""
23
+
24
+ @abstractmethod
25
+ def get(self, *, username: str) -> User:
26
+ """Get a user profile.
27
+
28
+ :param username: GitCode username or login.
29
+ :returns: User profile details.
30
+ """
31
+
32
+ @abstractmethod
33
+ def me(self) -> User:
34
+ """Get the profile of the authenticated user.
35
+
36
+ :returns: Authorized user profile.
37
+ """
38
+
39
+ @abstractmethod
40
+ def list_emails(self) -> List[Email]:
41
+ """List email addresses for the authenticated user.
42
+
43
+ :returns: Email records associated with the current account.
44
+ """
45
+
46
+ @abstractmethod
47
+ def list_events(
48
+ self, *, username: str, year: Optional[str] = None, next: Optional[str] = None
49
+ ) -> UserEventsResponse:
50
+ """List activity events for a user.
51
+
52
+ :param username: GitCode username or login (path segment, see User API).
53
+ :param year: Optional start year filter (query ``year``, e.g. ``2024`` per documentation).
54
+ :param next: Optional end date / pagination cursor (query ``next``; often an ISO timestamp from a prior page).
55
+ :returns: Event payload grouped by date.
56
+ """
57
+
58
+ @abstractmethod
59
+ def list_repos(self, *, username: str, **params) -> List[Repository]:
60
+ """List public repositories owned by a user.
61
+
62
+ Supported filters follow the user repository API documentation, such as
63
+ ``type``, ``sort``, ``direction``, ``page``, and ``per_page``.
64
+
65
+ :param username: GitCode username or login.
66
+ :param params: Query parameters accepted by the REST endpoint.
67
+ :returns: Matching repositories.
68
+ """
69
+
70
+ @abstractmethod
71
+ def create_key(self, *, key: str, title: str) -> PublicKey:
72
+ """Add a public SSH key for the authenticated user.
73
+
74
+ :param key: Public key material.
75
+ :param title: Human-readable key name.
76
+ :returns: Created key metadata.
77
+ """
78
+
79
+ @abstractmethod
80
+ def list_keys(self, *, page: Optional[int] = None, per_page: Optional[int] = None) -> List[APIObject]:
81
+ """List public SSH keys for the authenticated user.
82
+
83
+ :param page: Page number.
84
+ :param per_page: Page size.
85
+ :returns: Public key records.
86
+ """
87
+
88
+ @abstractmethod
89
+ def delete_key(self, *, key_id: Union[int, str]) -> None:
90
+ """Delete a public SSH key.
91
+
92
+ :param key_id: Public key identifier.
93
+ """
94
+
95
+ @abstractmethod
96
+ def get_key(self, *, key_id: Union[int, str]) -> PublicKey:
97
+ """Get a single public SSH key.
98
+
99
+ :param key_id: Public key identifier.
100
+ :returns: Public key metadata.
101
+ """
102
+
103
+ @abstractmethod
104
+ def get_namespace(self, *, path: str) -> Namespace:
105
+ """Resolve namespace information for the authenticated user.
106
+
107
+ :param path: Namespace path to look up.
108
+ :returns: Namespace details.
109
+ """
110
+
111
+ @abstractmethod
112
+ def list_starred(
113
+ self,
114
+ *,
115
+ sort: Optional[str] = None,
116
+ direction: Optional[str] = None,
117
+ page: Optional[int] = None,
118
+ per_page: Optional[int] = None,
119
+ ) -> List[Repository]:
120
+ """List repositories starred by the authenticated user.
121
+
122
+ :param sort: Sort field such as ``created`` or ``updated``.
123
+ :param direction: Sort direction, usually ``asc`` or ``desc``.
124
+ :param page: Page number.
125
+ :param per_page: Page size.
126
+ :returns: Starred repositories.
127
+ """
128
+
129
+
130
+ class UsersResource(SyncResource, AbstractUsersResource):
131
+ """Synchronous user and account endpoints."""
132
+
133
+ def get(self, *, username: str) -> User:
134
+ return self._model("GET", self._client._path("users", username), User)
135
+
136
+ def me(self) -> User:
137
+ return self._model("GET", self._client._path("user"), User)
138
+
139
+ def list_emails(self) -> List[Email]:
140
+ return self._models("GET", self._client._path("emails"), Email)
141
+
142
+ def list_events(
143
+ self, *, username: str, year: Optional[str] = None, next: Optional[str] = None
144
+ ) -> UserEventsResponse:
145
+ return self._model(
146
+ "GET",
147
+ self._client._path("users", username, "events"),
148
+ UserEventsResponse,
149
+ params={"year": year, "next": next},
150
+ )
151
+
152
+ def list_repos(self, *, username: str, **params) -> List[Repository]:
153
+ return self._models("GET", self._client._path("users", username, "repos"), Repository, params=params)
154
+
155
+ def create_key(self, *, key: str, title: str) -> PublicKey:
156
+ return self._model("POST", self._client._path("user", "keys"), PublicKey, json={"key": key, "title": title})
157
+
158
+ def list_keys(self, *, page: Optional[int] = None, per_page: Optional[int] = None) -> List[APIObject]:
159
+ data = self._request("GET", self._client._path("user", "keys"), params={"page": page, "per_page": per_page})
160
+ return [APIObject(dict(item)) for item in data]
161
+
162
+ def delete_key(self, *, key_id: Union[int, str]) -> None:
163
+ self._request("DELETE", self._client._path("user", "keys", key_id))
164
+
165
+ def get_key(self, *, key_id: Union[int, str]) -> PublicKey:
166
+ return self._model("GET", self._client._path("user", "keys", key_id), PublicKey)
167
+
168
+ def get_namespace(self, *, path: str) -> Namespace:
169
+ return self._model("GET", self._client._path("user", "namespace"), Namespace, params={"path": path})
170
+
171
+ def list_starred(
172
+ self,
173
+ *,
174
+ sort: Optional[str] = None,
175
+ direction: Optional[str] = None,
176
+ page: Optional[int] = None,
177
+ per_page: Optional[int] = None,
178
+ ) -> List[Repository]:
179
+ return self._models(
180
+ "GET",
181
+ self._client._path("user", "starred"),
182
+ Repository,
183
+ params={"sort": sort, "direction": direction, "page": page, "per_page": per_page},
184
+ )
185
+
186
+
187
+ class AsyncUsersResource(AsyncResource, AbstractUsersResource):
188
+ """Asynchronous user and account endpoints.
189
+
190
+ Mirrors :class:`UsersResource`; see that class for full parameter descriptions
191
+ (``docs/rest_api/users`` and related guides).
192
+ """
193
+
194
+ async def get(self, *, username: str) -> User:
195
+ return await self._model("GET", self._client._path("users", username), User)
196
+
197
+ async def me(self) -> User:
198
+ return await self._model("GET", self._client._path("user"), User)
199
+
200
+ async def list_emails(self) -> List[Email]:
201
+ return await self._models("GET", self._client._path("emails"), Email)
202
+
203
+ async def list_events(
204
+ self, *, username: str, year: Optional[str] = None, next: Optional[str] = None
205
+ ) -> UserEventsResponse:
206
+ return await self._model(
207
+ "GET",
208
+ self._client._path("users", username, "events"),
209
+ UserEventsResponse,
210
+ params={"year": year, "next": next},
211
+ )
212
+
213
+ async def list_repos(self, *, username: str, **params) -> List[Repository]:
214
+ return await self._models("GET", self._client._path("users", username, "repos"), Repository, params=params)
215
+
216
+ async def create_key(self, *, key: str, title: str) -> PublicKey:
217
+ return await self._model(
218
+ "POST", self._client._path("user", "keys"), PublicKey, json={"key": key, "title": title}
219
+ )
220
+
221
+ async def list_keys(self, *, page: Optional[int] = None, per_page: Optional[int] = None) -> List[APIObject]:
222
+ data = await self._request(
223
+ "GET", self._client._path("user", "keys"), params={"page": page, "per_page": per_page}
224
+ )
225
+ return [APIObject(dict(item)) for item in data]
226
+
227
+ async def delete_key(self, *, key_id: Union[int, str]) -> None:
228
+ await self._request("DELETE", self._client._path("user", "keys", key_id))
229
+
230
+ async def get_key(self, *, key_id: Union[int, str]) -> PublicKey:
231
+ return await self._model("GET", self._client._path("user", "keys", key_id), PublicKey)
232
+
233
+ async def get_namespace(self, *, path: str) -> Namespace:
234
+ return await self._model("GET", self._client._path("user", "namespace"), Namespace, params={"path": path})
235
+
236
+ async def list_starred(
237
+ self,
238
+ *,
239
+ sort: Optional[str] = None,
240
+ direction: Optional[str] = None,
241
+ page: Optional[int] = None,
242
+ per_page: Optional[int] = None,
243
+ ) -> List[Repository]:
244
+ return await self._models(
245
+ "GET",
246
+ self._client._path("user", "starred"),
247
+ Repository,
248
+ params={"sort": sort, "direction": direction, "page": page, "per_page": per_page},
249
+ )
@@ -0,0 +1,20 @@
1
+ """Classes for resource groups: issues, labels, members, milestones, and pull requests."""
2
+
3
+ from .issues_resource_group import AsyncIssuesResource, IssuesResource
4
+ from .labels_resource_group import AsyncLabelsResource, LabelsResource
5
+ from .members_resource_group import AsyncMembersResource, MembersResource
6
+ from .milestones_resource_group import AsyncMilestonesResource, MilestonesResource
7
+ from .pulls_resource_group import AsyncPullsResource, PullsResource
8
+
9
+ __all__ = [
10
+ "AsyncIssuesResource",
11
+ "AsyncLabelsResource",
12
+ "AsyncMembersResource",
13
+ "AsyncMilestonesResource",
14
+ "AsyncPullsResource",
15
+ "IssuesResource",
16
+ "LabelsResource",
17
+ "MembersResource",
18
+ "MilestonesResource",
19
+ "PullsResource",
20
+ ]
@@ -0,0 +1,10 @@
1
+ """Shared helpers for collaboration resource groups."""
2
+
3
+ from typing import List, Optional
4
+
5
+
6
+ def _comma_join(values: Optional[List[str]]) -> Optional[str]:
7
+ """Join a list of strings into the comma-separated format used by the API."""
8
+ if not values:
9
+ return None
10
+ return ",".join(values)