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.
- gitcode_api/__init__.py +8 -2
- gitcode_api/_base_client.py +7 -2
- gitcode_api/_exceptions.py +8 -0
- gitcode_api/exceptions.py +19 -0
- gitcode_api/llm/mcp.py +5 -5
- gitcode_api/models.py +205 -0
- gitcode_api/resources/__init__.py +1 -1
- gitcode_api/resources/_shared/__init__.py +18 -0
- gitcode_api/resources/_shared/base.py +129 -0
- gitcode_api/resources/{_shared.py → _shared/fetch_template.py} +133 -259
- gitcode_api/resources/account/__init__.py +17 -0
- gitcode_api/resources/account/oauth_resource_group.py +159 -0
- gitcode_api/resources/account/orgs_resource_group.py +422 -0
- gitcode_api/resources/account/search_resource_group.py +236 -0
- gitcode_api/resources/account/users_resource_group.py +249 -0
- gitcode_api/resources/collaboration/__init__.py +20 -0
- gitcode_api/resources/collaboration/_helpers.py +10 -0
- gitcode_api/resources/collaboration/issues_resource_group.py +855 -0
- gitcode_api/resources/collaboration/labels_resource_group.py +248 -0
- gitcode_api/resources/collaboration/members_resource_group.py +195 -0
- gitcode_api/resources/collaboration/milestones_resource_group.py +192 -0
- gitcode_api/resources/collaboration/pulls_resource_group.py +1300 -0
- gitcode_api/resources/misc/__init__.py +14 -0
- gitcode_api/resources/misc/releases_resource_group.py +445 -0
- gitcode_api/resources/misc/tags_resource_group.py +286 -0
- gitcode_api/resources/misc/webhooks_resource_group.py +192 -0
- gitcode_api/resources/repositories/__init__.py +17 -0
- gitcode_api/resources/repositories/branches_resource_group.py +151 -0
- gitcode_api/resources/repositories/commits_resource_group.py +333 -0
- gitcode_api/resources/repositories/repo_contents_resource_group.py +459 -0
- gitcode_api/resources/repositories/repos_resource_group.py +1279 -0
- gitcode_api/version.txt +1 -1
- {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/METADATA +3 -3
- gitcode_api-1.3.0.dist-info/RECORD +52 -0
- gitcode_api/resources/account.py +0 -1086
- gitcode_api/resources/collaboration.py +0 -2818
- gitcode_api/resources/misc.py +0 -901
- gitcode_api/resources/repositories.py +0 -2197
- gitcode_api-1.2.20.dist-info/RECORD +0 -31
- {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/WHEEL +0 -0
- {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/entry_points.txt +0 -0
- {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/licenses/LICENSE +0 -0
- {gitcode_api-1.2.20.dist-info → gitcode_api-1.3.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""AbstractTagsResource, TagsResource, and AsyncTagsResource resource group."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from ..._models import ProtectedTag, Tag
|
|
7
|
+
from .._shared import AsyncResource, SyncResource
|
|
8
|
+
|
|
9
|
+
# mypy: disable-error-code=override
|
|
10
|
+
# pylint: disable=invalid-overridden-method,protected-access,redefined-builtin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AbstractTagsResource(ABC):
|
|
14
|
+
"""Interface for Tags resource endpoints."""
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def list(
|
|
18
|
+
self,
|
|
19
|
+
*,
|
|
20
|
+
owner: Optional[str] = None,
|
|
21
|
+
repo: Optional[str] = None,
|
|
22
|
+
page: Optional[int] = None,
|
|
23
|
+
per_page: Optional[int] = None,
|
|
24
|
+
) -> List[Tag]:
|
|
25
|
+
"""List tags for a repository.
|
|
26
|
+
|
|
27
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
28
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
29
|
+
:param page: Page number.
|
|
30
|
+
:param per_page: Page size.
|
|
31
|
+
:returns: Tags.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def create(
|
|
36
|
+
self,
|
|
37
|
+
*,
|
|
38
|
+
refs: str,
|
|
39
|
+
tag_name: str,
|
|
40
|
+
owner: Optional[str] = None,
|
|
41
|
+
repo: Optional[str] = None,
|
|
42
|
+
tag_message: Optional[str] = None,
|
|
43
|
+
) -> Tag:
|
|
44
|
+
"""Create a tag for a repository.
|
|
45
|
+
|
|
46
|
+
:param refs: Object SHA or ref the tag should point to.
|
|
47
|
+
:param tag_name: Name of the new tag.
|
|
48
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
49
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
50
|
+
:param tag_message: Optional annotated tag message.
|
|
51
|
+
:returns: Created tag.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def list_protected(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
owner: Optional[str] = None,
|
|
59
|
+
repo: Optional[str] = None,
|
|
60
|
+
page: Optional[int] = None,
|
|
61
|
+
per_page: Optional[int] = None,
|
|
62
|
+
) -> List[ProtectedTag]:
|
|
63
|
+
"""List protected tags for a repository.
|
|
64
|
+
|
|
65
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
66
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
67
|
+
:param page: Page number.
|
|
68
|
+
:param per_page: Page size.
|
|
69
|
+
:returns: Protected tag rules.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
@abstractmethod
|
|
73
|
+
def delete_protected(self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
74
|
+
"""Delete a protected tag rule.
|
|
75
|
+
|
|
76
|
+
:param tag_name: Protected tag name in the URL path.
|
|
77
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
78
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def get_protected(self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None) -> ProtectedTag:
|
|
83
|
+
"""Get details for a protected tag rule.
|
|
84
|
+
|
|
85
|
+
:param tag_name: Tag name in the path.
|
|
86
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
87
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
88
|
+
:returns: Protected tag configuration.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def create_protected(
|
|
93
|
+
self,
|
|
94
|
+
*,
|
|
95
|
+
name: str,
|
|
96
|
+
owner: Optional[str] = None,
|
|
97
|
+
repo: Optional[str] = None,
|
|
98
|
+
create_access_level: Optional[int] = None,
|
|
99
|
+
) -> ProtectedTag:
|
|
100
|
+
"""Create a protected tag rule.
|
|
101
|
+
|
|
102
|
+
:param name: Tag name or pattern to protect.
|
|
103
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
104
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
105
|
+
:param create_access_level: Minimum access level required to create matching tags (API-specific integer).
|
|
106
|
+
:returns: Created rule.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
@abstractmethod
|
|
110
|
+
def update_protected(
|
|
111
|
+
self, *, name: str, create_access_level: int, owner: Optional[str] = None, repo: Optional[str] = None
|
|
112
|
+
) -> ProtectedTag:
|
|
113
|
+
"""Update a protected tag rule."""
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class TagsResource(SyncResource, AbstractTagsResource):
|
|
117
|
+
"""Synchronous tag endpoints."""
|
|
118
|
+
|
|
119
|
+
def list(
|
|
120
|
+
self,
|
|
121
|
+
*,
|
|
122
|
+
owner: Optional[str] = None,
|
|
123
|
+
repo: Optional[str] = None,
|
|
124
|
+
page: Optional[int] = None,
|
|
125
|
+
per_page: Optional[int] = None,
|
|
126
|
+
) -> List[Tag]:
|
|
127
|
+
return self._models(
|
|
128
|
+
"GET",
|
|
129
|
+
self._client._repo_path("tags", owner=owner, repo=repo),
|
|
130
|
+
Tag,
|
|
131
|
+
params={"page": page, "per_page": per_page},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def create(
|
|
135
|
+
self,
|
|
136
|
+
*,
|
|
137
|
+
refs: str,
|
|
138
|
+
tag_name: str,
|
|
139
|
+
owner: Optional[str] = None,
|
|
140
|
+
repo: Optional[str] = None,
|
|
141
|
+
tag_message: Optional[str] = None,
|
|
142
|
+
) -> Tag:
|
|
143
|
+
return self._model(
|
|
144
|
+
"POST",
|
|
145
|
+
self._client._repo_path("tags", owner=owner, repo=repo),
|
|
146
|
+
Tag,
|
|
147
|
+
json={"refs": refs, "tag_name": tag_name, "tag_message": tag_message},
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def list_protected(
|
|
151
|
+
self,
|
|
152
|
+
*,
|
|
153
|
+
owner: Optional[str] = None,
|
|
154
|
+
repo: Optional[str] = None,
|
|
155
|
+
page: Optional[int] = None,
|
|
156
|
+
per_page: Optional[int] = None,
|
|
157
|
+
) -> List[ProtectedTag]:
|
|
158
|
+
return self._models(
|
|
159
|
+
"GET",
|
|
160
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
161
|
+
ProtectedTag,
|
|
162
|
+
params={"page": page, "per_page": per_page},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def delete_protected(self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
166
|
+
self._request("DELETE", self._client._repo_path("protected_tags", tag_name, owner=owner, repo=repo))
|
|
167
|
+
|
|
168
|
+
def get_protected(self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None) -> ProtectedTag:
|
|
169
|
+
return self._model(
|
|
170
|
+
"GET",
|
|
171
|
+
self._client._repo_path("protected_tags", tag_name, owner=owner, repo=repo),
|
|
172
|
+
ProtectedTag,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def create_protected(
|
|
176
|
+
self,
|
|
177
|
+
*,
|
|
178
|
+
name: str,
|
|
179
|
+
owner: Optional[str] = None,
|
|
180
|
+
repo: Optional[str] = None,
|
|
181
|
+
create_access_level: Optional[int] = None,
|
|
182
|
+
) -> ProtectedTag:
|
|
183
|
+
return self._model(
|
|
184
|
+
"POST",
|
|
185
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
186
|
+
ProtectedTag,
|
|
187
|
+
json={"name": name, "create_access_level": create_access_level},
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def update_protected(
|
|
191
|
+
self, *, name: str, create_access_level: int, owner: Optional[str] = None, repo: Optional[str] = None
|
|
192
|
+
) -> ProtectedTag:
|
|
193
|
+
return self._model(
|
|
194
|
+
"PUT",
|
|
195
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
196
|
+
ProtectedTag,
|
|
197
|
+
json={"name": name, "create_access_level": create_access_level},
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class AsyncTagsResource(AsyncResource, AbstractTagsResource):
|
|
202
|
+
"""Asynchronous tag endpoints.
|
|
203
|
+
|
|
204
|
+
Mirrors :class:`TagsResource`; see that class and ``docs/rest_api/repos/tag`` for semantics.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
async def list(
|
|
208
|
+
self,
|
|
209
|
+
*,
|
|
210
|
+
owner: Optional[str] = None,
|
|
211
|
+
repo: Optional[str] = None,
|
|
212
|
+
page: Optional[int] = None,
|
|
213
|
+
per_page: Optional[int] = None,
|
|
214
|
+
) -> List[Tag]:
|
|
215
|
+
return await self._models(
|
|
216
|
+
"GET",
|
|
217
|
+
self._client._repo_path("tags", owner=owner, repo=repo),
|
|
218
|
+
Tag,
|
|
219
|
+
params={"page": page, "per_page": per_page},
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
async def create(
|
|
223
|
+
self,
|
|
224
|
+
*,
|
|
225
|
+
refs: str,
|
|
226
|
+
tag_name: str,
|
|
227
|
+
owner: Optional[str] = None,
|
|
228
|
+
repo: Optional[str] = None,
|
|
229
|
+
tag_message: Optional[str] = None,
|
|
230
|
+
) -> Tag:
|
|
231
|
+
return await self._model(
|
|
232
|
+
"POST",
|
|
233
|
+
self._client._repo_path("tags", owner=owner, repo=repo),
|
|
234
|
+
Tag,
|
|
235
|
+
json={"refs": refs, "tag_name": tag_name, "tag_message": tag_message},
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
async def list_protected(
|
|
239
|
+
self,
|
|
240
|
+
*,
|
|
241
|
+
owner: Optional[str] = None,
|
|
242
|
+
repo: Optional[str] = None,
|
|
243
|
+
page: Optional[int] = None,
|
|
244
|
+
per_page: Optional[int] = None,
|
|
245
|
+
) -> List[ProtectedTag]:
|
|
246
|
+
return await self._models(
|
|
247
|
+
"GET",
|
|
248
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
249
|
+
ProtectedTag,
|
|
250
|
+
params={"page": page, "per_page": per_page},
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
async def delete_protected(self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
254
|
+
await self._request("DELETE", self._client._repo_path("protected_tags", tag_name, owner=owner, repo=repo))
|
|
255
|
+
|
|
256
|
+
async def get_protected(
|
|
257
|
+
self, *, tag_name: str, owner: Optional[str] = None, repo: Optional[str] = None
|
|
258
|
+
) -> ProtectedTag:
|
|
259
|
+
return await self._model(
|
|
260
|
+
"GET", self._client._repo_path("protected_tags", tag_name, owner=owner, repo=repo), ProtectedTag
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
async def create_protected(
|
|
264
|
+
self,
|
|
265
|
+
*,
|
|
266
|
+
name: str,
|
|
267
|
+
owner: Optional[str] = None,
|
|
268
|
+
repo: Optional[str] = None,
|
|
269
|
+
create_access_level: Optional[int] = None,
|
|
270
|
+
) -> ProtectedTag:
|
|
271
|
+
return await self._model(
|
|
272
|
+
"POST",
|
|
273
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
274
|
+
ProtectedTag,
|
|
275
|
+
json={"name": name, "create_access_level": create_access_level},
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
async def update_protected(
|
|
279
|
+
self, *, name: str, create_access_level: int, owner: Optional[str] = None, repo: Optional[str] = None
|
|
280
|
+
) -> ProtectedTag:
|
|
281
|
+
return await self._model(
|
|
282
|
+
"PUT",
|
|
283
|
+
self._client._repo_path("protected_tags", owner=owner, repo=repo),
|
|
284
|
+
ProtectedTag,
|
|
285
|
+
json={"name": name, "create_access_level": create_access_level},
|
|
286
|
+
)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""AbstractWebhooksResource, WebhooksResource, and AsyncWebhooksResource resource group."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import List, Optional, Union
|
|
5
|
+
|
|
6
|
+
from ..._models import Webhook
|
|
7
|
+
from .._shared import AsyncResource, SyncResource
|
|
8
|
+
|
|
9
|
+
# mypy: disable-error-code=override
|
|
10
|
+
# pylint: disable=invalid-overridden-method,protected-access,redefined-builtin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AbstractWebhooksResource(ABC):
|
|
14
|
+
"""Interface for Webhooks resource endpoints."""
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def list(
|
|
18
|
+
self,
|
|
19
|
+
*,
|
|
20
|
+
owner: Optional[str] = None,
|
|
21
|
+
repo: Optional[str] = None,
|
|
22
|
+
page: Optional[int] = None,
|
|
23
|
+
per_page: Optional[int] = None,
|
|
24
|
+
) -> List[Webhook]:
|
|
25
|
+
"""List webhooks for a repository.
|
|
26
|
+
|
|
27
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
28
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
29
|
+
:param page: Page number.
|
|
30
|
+
:param per_page: Page size.
|
|
31
|
+
:returns: Hook configurations.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def create(self, *, url: str, owner: Optional[str] = None, repo: Optional[str] = None, **payload) -> Webhook:
|
|
36
|
+
"""Create a repository webhook.
|
|
37
|
+
|
|
38
|
+
:param url: Payload URL GitCode should POST events to.
|
|
39
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
40
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
41
|
+
:param payload: Additional fields from the Webhooks API (events list, secret, content type, etc.).
|
|
42
|
+
:returns: Created webhook.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def get(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> Webhook:
|
|
47
|
+
"""Get a repository webhook by identifier.
|
|
48
|
+
|
|
49
|
+
:param hook_id: Webhook id from the API.
|
|
50
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
51
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
52
|
+
:returns: Webhook configuration.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
@abstractmethod
|
|
56
|
+
def update(
|
|
57
|
+
self,
|
|
58
|
+
*,
|
|
59
|
+
hook_id: Union[int, str],
|
|
60
|
+
url: str,
|
|
61
|
+
owner: Optional[str] = None,
|
|
62
|
+
repo: Optional[str] = None,
|
|
63
|
+
**payload,
|
|
64
|
+
) -> Webhook:
|
|
65
|
+
"""Update a repository webhook.
|
|
66
|
+
|
|
67
|
+
:param hook_id: Webhook id.
|
|
68
|
+
:param url: New payload URL (merged into the JSON body).
|
|
69
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
70
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
71
|
+
:param payload: Other mutable webhook fields accepted by the API.
|
|
72
|
+
:returns: Updated webhook.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def delete(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
77
|
+
"""Delete a repository webhook.
|
|
78
|
+
|
|
79
|
+
:param hook_id: Webhook id.
|
|
80
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
81
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
@abstractmethod
|
|
85
|
+
def test(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
86
|
+
"""Send a test delivery for a repository webhook.
|
|
87
|
+
|
|
88
|
+
:param hook_id: Webhook id.
|
|
89
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
90
|
+
:param repo: Repository path. Uses the client default when omitted.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class WebhooksResource(SyncResource, AbstractWebhooksResource):
|
|
95
|
+
"""Synchronous webhook endpoints."""
|
|
96
|
+
|
|
97
|
+
def list(
|
|
98
|
+
self,
|
|
99
|
+
*,
|
|
100
|
+
owner: Optional[str] = None,
|
|
101
|
+
repo: Optional[str] = None,
|
|
102
|
+
page: Optional[int] = None,
|
|
103
|
+
per_page: Optional[int] = None,
|
|
104
|
+
) -> List[Webhook]:
|
|
105
|
+
return self._models(
|
|
106
|
+
"GET",
|
|
107
|
+
self._client._repo_path("hooks", owner=owner, repo=repo),
|
|
108
|
+
Webhook,
|
|
109
|
+
params={"page": page, "per_page": per_page},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def create(self, *, url: str, owner: Optional[str] = None, repo: Optional[str] = None, **payload) -> Webhook:
|
|
113
|
+
payload["url"] = url
|
|
114
|
+
return self._model("POST", self._client._repo_path("hooks", owner=owner, repo=repo), Webhook, json=payload)
|
|
115
|
+
|
|
116
|
+
def get(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> Webhook:
|
|
117
|
+
return self._model("GET", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo), Webhook)
|
|
118
|
+
|
|
119
|
+
def update(
|
|
120
|
+
self,
|
|
121
|
+
*,
|
|
122
|
+
hook_id: Union[int, str],
|
|
123
|
+
url: str,
|
|
124
|
+
owner: Optional[str] = None,
|
|
125
|
+
repo: Optional[str] = None,
|
|
126
|
+
**payload,
|
|
127
|
+
) -> Webhook:
|
|
128
|
+
payload["url"] = url
|
|
129
|
+
return self._model(
|
|
130
|
+
"PATCH", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo), Webhook, json=payload
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def delete(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
134
|
+
self._request("DELETE", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo))
|
|
135
|
+
|
|
136
|
+
def test(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
137
|
+
self._request("POST", self._client._repo_path("hooks", hook_id, "tests", owner=owner, repo=repo))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class AsyncWebhooksResource(AsyncResource, AbstractWebhooksResource):
|
|
141
|
+
"""Asynchronous webhook endpoints.
|
|
142
|
+
|
|
143
|
+
Mirrors :class:`WebhooksResource`; see that class and ``docs/rest_api/repos/webhooks``.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
async def list(
|
|
147
|
+
self,
|
|
148
|
+
*,
|
|
149
|
+
owner: Optional[str] = None,
|
|
150
|
+
repo: Optional[str] = None,
|
|
151
|
+
page: Optional[int] = None,
|
|
152
|
+
per_page: Optional[int] = None,
|
|
153
|
+
) -> List[Webhook]:
|
|
154
|
+
return await self._models(
|
|
155
|
+
"GET",
|
|
156
|
+
self._client._repo_path("hooks", owner=owner, repo=repo),
|
|
157
|
+
Webhook,
|
|
158
|
+
params={"page": page, "per_page": per_page},
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
async def create(self, *, url: str, owner: Optional[str] = None, repo: Optional[str] = None, **payload) -> Webhook:
|
|
162
|
+
payload["url"] = url
|
|
163
|
+
return await self._model(
|
|
164
|
+
"POST", self._client._repo_path("hooks", owner=owner, repo=repo), Webhook, json=payload
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
async def get(
|
|
168
|
+
self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None
|
|
169
|
+
) -> Webhook:
|
|
170
|
+
return await self._model("GET", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo), Webhook)
|
|
171
|
+
|
|
172
|
+
async def update(
|
|
173
|
+
self,
|
|
174
|
+
*,
|
|
175
|
+
hook_id: Union[int, str],
|
|
176
|
+
url: str,
|
|
177
|
+
owner: Optional[str] = None,
|
|
178
|
+
repo: Optional[str] = None,
|
|
179
|
+
**payload,
|
|
180
|
+
) -> Webhook:
|
|
181
|
+
payload["url"] = url
|
|
182
|
+
return await self._model(
|
|
183
|
+
"PATCH", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo), Webhook, json=payload
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
async def delete(
|
|
187
|
+
self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None
|
|
188
|
+
) -> None:
|
|
189
|
+
await self._request("DELETE", self._client._repo_path("hooks", hook_id, owner=owner, repo=repo))
|
|
190
|
+
|
|
191
|
+
async def test(self, *, hook_id: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> None:
|
|
192
|
+
await self._request("POST", self._client._repo_path("hooks", hook_id, "tests", owner=owner, repo=repo))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Classes for resource groups: branches, commits, file contents, and repositories."""
|
|
2
|
+
|
|
3
|
+
from .branches_resource_group import AsyncBranchesResource, BranchesResource
|
|
4
|
+
from .commits_resource_group import AsyncCommitsResource, CommitsResource
|
|
5
|
+
from .repo_contents_resource_group import AsyncRepoContentsResource, RepoContentsResource
|
|
6
|
+
from .repos_resource_group import AsyncReposResource, ReposResource
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"AsyncBranchesResource",
|
|
10
|
+
"AsyncCommitsResource",
|
|
11
|
+
"AsyncRepoContentsResource",
|
|
12
|
+
"AsyncReposResource",
|
|
13
|
+
"BranchesResource",
|
|
14
|
+
"CommitsResource",
|
|
15
|
+
"RepoContentsResource",
|
|
16
|
+
"ReposResource",
|
|
17
|
+
]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""AbstractBranchesResource, BranchesResource, and AsyncBranchesResource resource group."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from ..._models import (
|
|
7
|
+
Branch,
|
|
8
|
+
BranchDetail,
|
|
9
|
+
ProtectedBranch,
|
|
10
|
+
)
|
|
11
|
+
from .._shared import AsyncResource, SyncResource
|
|
12
|
+
|
|
13
|
+
# mypy: disable-error-code=override
|
|
14
|
+
# pylint: disable=invalid-overridden-method,protected-access,redefined-builtin
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AbstractBranchesResource(ABC):
|
|
18
|
+
"""Interface for Branches resource endpoints."""
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def list(
|
|
22
|
+
self,
|
|
23
|
+
*,
|
|
24
|
+
owner: Optional[str] = None,
|
|
25
|
+
repo: Optional[str] = None,
|
|
26
|
+
sort: Optional[str] = None,
|
|
27
|
+
direction: Optional[str] = None,
|
|
28
|
+
page: Optional[int] = None,
|
|
29
|
+
per_page: Optional[int] = None,
|
|
30
|
+
) -> List[Branch]:
|
|
31
|
+
"""List branches in a repository.
|
|
32
|
+
|
|
33
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
34
|
+
:param repo: Repository name. Uses the client default when omitted.
|
|
35
|
+
:param sort: Optional sort field such as ``name`` or ``updated``.
|
|
36
|
+
:param direction: Sort direction, usually ``asc`` or ``desc``.
|
|
37
|
+
:param page: Page number.
|
|
38
|
+
:param per_page: Page size.
|
|
39
|
+
:returns: Repository branches.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
@abstractmethod
|
|
43
|
+
def get(self, *, branch: str, owner: Optional[str] = None, repo: Optional[str] = None) -> BranchDetail:
|
|
44
|
+
"""Get a single branch.
|
|
45
|
+
|
|
46
|
+
:param branch: Branch name.
|
|
47
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
48
|
+
:param repo: Repository name. Uses the client default when omitted.
|
|
49
|
+
:returns: Branch details.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@abstractmethod
|
|
53
|
+
def create(self, *, branch: str, ref: str, owner: Optional[str] = None, repo: Optional[str] = None) -> Branch:
|
|
54
|
+
"""Create a branch from an existing ref.
|
|
55
|
+
|
|
56
|
+
:param branch: New branch name.
|
|
57
|
+
:param ref: Starting ref such as a branch, tag, or commit SHA.
|
|
58
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
59
|
+
:param repo: Repository name. Uses the client default when omitted.
|
|
60
|
+
:returns: Created branch details.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
@abstractmethod
|
|
64
|
+
def list_protected(self, *, owner: Optional[str] = None, repo: Optional[str] = None) -> List[ProtectedBranch]:
|
|
65
|
+
"""List protected branch rules for a repository.
|
|
66
|
+
|
|
67
|
+
:param owner: Repository owner path. Uses the client default when omitted.
|
|
68
|
+
:param repo: Repository name. Uses the client default when omitted.
|
|
69
|
+
:returns: Protected branch rules.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class BranchesResource(SyncResource, AbstractBranchesResource):
|
|
74
|
+
"""Synchronous branch endpoints."""
|
|
75
|
+
|
|
76
|
+
def list(
|
|
77
|
+
self,
|
|
78
|
+
*,
|
|
79
|
+
owner: Optional[str] = None,
|
|
80
|
+
repo: Optional[str] = None,
|
|
81
|
+
sort: Optional[str] = None,
|
|
82
|
+
direction: Optional[str] = None,
|
|
83
|
+
page: Optional[int] = None,
|
|
84
|
+
per_page: Optional[int] = None,
|
|
85
|
+
) -> List[Branch]:
|
|
86
|
+
return self._models(
|
|
87
|
+
"GET",
|
|
88
|
+
self._client._repo_path("branches", owner=owner, repo=repo),
|
|
89
|
+
Branch,
|
|
90
|
+
params={"sort": sort, "direction": direction, "page": page, "per_page": per_page},
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def get(self, *, branch: str, owner: Optional[str] = None, repo: Optional[str] = None) -> BranchDetail:
|
|
94
|
+
return self._model("GET", self._client._repo_path("branches", branch, owner=owner, repo=repo), BranchDetail)
|
|
95
|
+
|
|
96
|
+
def create(self, *, branch: str, ref: str, owner: Optional[str] = None, repo: Optional[str] = None) -> Branch:
|
|
97
|
+
return self._model(
|
|
98
|
+
"POST",
|
|
99
|
+
self._client._repo_path("branches", owner=owner, repo=repo),
|
|
100
|
+
Branch,
|
|
101
|
+
json={"branch_name": branch, "refs": ref},
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
def list_protected(self, *, owner: Optional[str] = None, repo: Optional[str] = None) -> List[ProtectedBranch]:
|
|
105
|
+
return self._models(
|
|
106
|
+
"GET",
|
|
107
|
+
self._client._repo_path("protect_branches", owner=owner, repo=repo),
|
|
108
|
+
ProtectedBranch,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class AsyncBranchesResource(AsyncResource, AbstractBranchesResource):
|
|
113
|
+
"""Asynchronous branch endpoints.
|
|
114
|
+
|
|
115
|
+
Mirrors :class:`BranchesResource` (``docs/rest_api/repos/branch``).
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
async def list(
|
|
119
|
+
self,
|
|
120
|
+
*,
|
|
121
|
+
owner: Optional[str] = None,
|
|
122
|
+
repo: Optional[str] = None,
|
|
123
|
+
sort: Optional[str] = None,
|
|
124
|
+
direction: Optional[str] = None,
|
|
125
|
+
page: Optional[int] = None,
|
|
126
|
+
per_page: Optional[int] = None,
|
|
127
|
+
) -> List[Branch]:
|
|
128
|
+
return await self._models(
|
|
129
|
+
"GET",
|
|
130
|
+
self._client._repo_path("branches", owner=owner, repo=repo),
|
|
131
|
+
Branch,
|
|
132
|
+
params={"sort": sort, "direction": direction, "page": page, "per_page": per_page},
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
async def get(self, *, branch: str, owner: Optional[str] = None, repo: Optional[str] = None) -> BranchDetail:
|
|
136
|
+
return await self._model(
|
|
137
|
+
"GET", self._client._repo_path("branches", branch, owner=owner, repo=repo), BranchDetail
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
async def create(self, *, branch: str, ref: str, owner: Optional[str] = None, repo: Optional[str] = None) -> Branch:
|
|
141
|
+
return await self._model(
|
|
142
|
+
"POST",
|
|
143
|
+
self._client._repo_path("branches", owner=owner, repo=repo),
|
|
144
|
+
Branch,
|
|
145
|
+
json={"branch_name": branch, "refs": ref},
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
async def list_protected(self, *, owner: Optional[str] = None, repo: Optional[str] = None) -> List[ProtectedBranch]:
|
|
149
|
+
return await self._models(
|
|
150
|
+
"GET", self._client._repo_path("protect_branches", owner=owner, repo=repo), ProtectedBranch
|
|
151
|
+
)
|