gitcode-api 1.1.1__tar.gz → 1.1.2__tar.gz
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-1.1.1 → gitcode_api-1.1.2}/PKG-INFO +25 -25
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/README.md +24 -24
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/_base_client.py +18 -12
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/_client.py +7 -1
- gitcode_api-1.1.2/gitcode_api/version.txt +1 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api.egg-info/PKG-INFO +25 -25
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api.egg-info/SOURCES.txt +1 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/pyproject.toml +2 -2
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/LICENSE +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/__init__.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/_exceptions.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/_models.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/__init__.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/_shared.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/account.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/collaboration.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/misc.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api/resources/repositories.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api.egg-info/dependency_links.txt +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api.egg-info/requires.txt +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/gitcode_api.egg-info/top_level.txt +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/setup.cfg +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_base_client.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_client.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_models.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_resources_account.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_resources_collaboration.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_resources_misc.py +0 -0
- {gitcode_api-1.1.1 → gitcode_api-1.1.2}/tests/test_resources_repositories.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: Easy to use Python SDK for the GitCode REST API, community-maintained.
|
|
5
5
|
Author-email: Hugo Huang <hugo@hugohuang.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,9 +27,9 @@ Dynamic: license-file
|
|
|
27
27
|
|
|
28
28
|
# GitCode-API
|
|
29
29
|
|
|
30
|
-
   ](https://pypi.org/project/gitcode-api) [](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API) [](https://pepy.tech/projects/gitcode-api)
|
|
31
31
|
|
|
32
|
-
  
|
|
32
|
+
[](https://gitcode-api.readthedocs.io) [](README.zh.md) [](README.md)
|
|
33
33
|
|
|
34
34
|
`gitcode-api` is a community-maintained Python SDK for the GitCode REST API. It provides easy-to-use synchronous and asynchronous clients, repository-scoped helpers, and lightweight response models so you can work with GitCode from Python without hand-writing raw HTTP requests.
|
|
35
35
|
|
|
@@ -57,6 +57,20 @@ Pass `api_key=` directly, or set `GITCODE_ACCESS_TOKEN` in your environment:
|
|
|
57
57
|
export GITCODE_ACCESS_TOKEN="your-token"
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
If your token is stored in encrypted form, pass `decrypt=` to decode either an
|
|
61
|
+
encrypted `api_key=` value or an encrypted `GITCODE_ACCESS_TOKEN` value before
|
|
62
|
+
the client uses it.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from gitcode_api import GitCode
|
|
66
|
+
from trusted_library import decrypt_token
|
|
67
|
+
|
|
68
|
+
client = GitCode(
|
|
69
|
+
api_key="encrypted-token",
|
|
70
|
+
decrypt=decrypt_token,
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
60
74
|
## Quick Start
|
|
61
75
|
|
|
62
76
|
### Sync client
|
|
@@ -69,40 +83,31 @@ client = GitCode(
|
|
|
69
83
|
repo="GitCode-API",
|
|
70
84
|
)
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
branches = client.branches.list(per_page=5)
|
|
86
|
+
repo = client.repos.get()
|
|
87
|
+
branches = client.branches.list(per_page=5)
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
finally:
|
|
80
|
-
client.close()
|
|
89
|
+
print(repo.full_name)
|
|
90
|
+
for branch in branches:
|
|
91
|
+
print(branch.name)
|
|
81
92
|
```
|
|
82
93
|
|
|
83
94
|
### Async client
|
|
84
95
|
|
|
85
96
|
```python
|
|
86
97
|
import asyncio
|
|
87
|
-
|
|
88
98
|
from gitcode_api import AsyncGitCode
|
|
89
99
|
|
|
90
|
-
|
|
91
100
|
async def main() -> None:
|
|
92
101
|
client = AsyncGitCode(owner="SushiNinja", repo="GitCode-API")
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
print(len(pulls))
|
|
96
|
-
finally:
|
|
97
|
-
await client.close()
|
|
98
|
-
|
|
102
|
+
pulls = await client.pulls.list(state="open", per_page=20)
|
|
103
|
+
print(len(pulls))
|
|
99
104
|
|
|
100
105
|
asyncio.run(main())
|
|
101
106
|
```
|
|
102
107
|
|
|
103
108
|
### Context managers
|
|
104
109
|
|
|
105
|
-
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`.
|
|
110
|
+
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`. Leaving the block calls `close()` / `await close()` on the underlying client automatically, including a custom `http_client=` you passed in.
|
|
106
111
|
|
|
107
112
|
```python
|
|
108
113
|
from gitcode_api import GitCode
|
|
@@ -114,21 +119,16 @@ with GitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
|
114
119
|
|
|
115
120
|
```python
|
|
116
121
|
import asyncio
|
|
117
|
-
|
|
118
122
|
from gitcode_api import AsyncGitCode
|
|
119
123
|
|
|
120
|
-
|
|
121
124
|
async def main() -> None:
|
|
122
125
|
async with AsyncGitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
123
126
|
pulls = await client.pulls.list(state="open", per_page=20)
|
|
124
127
|
print(len(pulls))
|
|
125
128
|
|
|
126
|
-
|
|
127
129
|
asyncio.run(main())
|
|
128
130
|
```
|
|
129
131
|
|
|
130
|
-
If you pass a custom `http_client=`, the SDK does not close it; you still own that client’s lifecycle (for example `async with httpx.AsyncClient(...) as http:` plus `AsyncGitCode(http_client=http)`).
|
|
131
|
-
|
|
132
132
|
## Common Workflows
|
|
133
133
|
|
|
134
134
|
Create a pull request:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# GitCode-API
|
|
2
2
|
|
|
3
|
-
   ](https://pypi.org/project/gitcode-api) [](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API) [](https://pepy.tech/projects/gitcode-api)
|
|
4
4
|
|
|
5
|
-
  
|
|
5
|
+
[](https://gitcode-api.readthedocs.io) [](README.zh.md) [](README.md)
|
|
6
6
|
|
|
7
7
|
`gitcode-api` is a community-maintained Python SDK for the GitCode REST API. It provides easy-to-use synchronous and asynchronous clients, repository-scoped helpers, and lightweight response models so you can work with GitCode from Python without hand-writing raw HTTP requests.
|
|
8
8
|
|
|
@@ -30,6 +30,20 @@ Pass `api_key=` directly, or set `GITCODE_ACCESS_TOKEN` in your environment:
|
|
|
30
30
|
export GITCODE_ACCESS_TOKEN="your-token"
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
If your token is stored in encrypted form, pass `decrypt=` to decode either an
|
|
34
|
+
encrypted `api_key=` value or an encrypted `GITCODE_ACCESS_TOKEN` value before
|
|
35
|
+
the client uses it.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from gitcode_api import GitCode
|
|
39
|
+
from trusted_library import decrypt_token
|
|
40
|
+
|
|
41
|
+
client = GitCode(
|
|
42
|
+
api_key="encrypted-token",
|
|
43
|
+
decrypt=decrypt_token,
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
33
47
|
## Quick Start
|
|
34
48
|
|
|
35
49
|
### Sync client
|
|
@@ -42,40 +56,31 @@ client = GitCode(
|
|
|
42
56
|
repo="GitCode-API",
|
|
43
57
|
)
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
branches = client.branches.list(per_page=5)
|
|
59
|
+
repo = client.repos.get()
|
|
60
|
+
branches = client.branches.list(per_page=5)
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
finally:
|
|
53
|
-
client.close()
|
|
62
|
+
print(repo.full_name)
|
|
63
|
+
for branch in branches:
|
|
64
|
+
print(branch.name)
|
|
54
65
|
```
|
|
55
66
|
|
|
56
67
|
### Async client
|
|
57
68
|
|
|
58
69
|
```python
|
|
59
70
|
import asyncio
|
|
60
|
-
|
|
61
71
|
from gitcode_api import AsyncGitCode
|
|
62
72
|
|
|
63
|
-
|
|
64
73
|
async def main() -> None:
|
|
65
74
|
client = AsyncGitCode(owner="SushiNinja", repo="GitCode-API")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
print(len(pulls))
|
|
69
|
-
finally:
|
|
70
|
-
await client.close()
|
|
71
|
-
|
|
75
|
+
pulls = await client.pulls.list(state="open", per_page=20)
|
|
76
|
+
print(len(pulls))
|
|
72
77
|
|
|
73
78
|
asyncio.run(main())
|
|
74
79
|
```
|
|
75
80
|
|
|
76
81
|
### Context managers
|
|
77
82
|
|
|
78
|
-
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`.
|
|
83
|
+
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`. Leaving the block calls `close()` / `await close()` on the underlying client automatically, including a custom `http_client=` you passed in.
|
|
79
84
|
|
|
80
85
|
```python
|
|
81
86
|
from gitcode_api import GitCode
|
|
@@ -87,21 +92,16 @@ with GitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
|
87
92
|
|
|
88
93
|
```python
|
|
89
94
|
import asyncio
|
|
90
|
-
|
|
91
95
|
from gitcode_api import AsyncGitCode
|
|
92
96
|
|
|
93
|
-
|
|
94
97
|
async def main() -> None:
|
|
95
98
|
async with AsyncGitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
96
99
|
pulls = await client.pulls.list(state="open", per_page=20)
|
|
97
100
|
print(len(pulls))
|
|
98
101
|
|
|
99
|
-
|
|
100
102
|
asyncio.run(main())
|
|
101
103
|
```
|
|
102
104
|
|
|
103
|
-
If you pass a custom `http_client=`, the SDK does not close it; you still own that client’s lifecycle (for example `async with httpx.AsyncClient(...) as http:` plus `AsyncGitCode(http_client=http)`).
|
|
104
|
-
|
|
105
105
|
## Common Workflows
|
|
106
106
|
|
|
107
107
|
Create a pull request:
|
|
@@ -5,7 +5,7 @@ payload cleanup, and response parsing for both sync and async clients.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import os
|
|
8
|
-
from typing import Any, Dict, Optional, Tuple, Union
|
|
8
|
+
from typing import Any, Callable, Dict, Optional, Tuple, Union
|
|
9
9
|
from urllib.parse import quote
|
|
10
10
|
|
|
11
11
|
import httpx
|
|
@@ -30,6 +30,7 @@ class BaseGitCodeClient:
|
|
|
30
30
|
:param repo: Default repository name for repository-scoped calls.
|
|
31
31
|
:param base_url: Base URL for the GitCode REST API.
|
|
32
32
|
:param timeout: Request timeout in seconds.
|
|
33
|
+
:param decrypt: Optional decryption function for encrypted access token.
|
|
33
34
|
"""
|
|
34
35
|
|
|
35
36
|
def __init__(
|
|
@@ -40,20 +41,23 @@ class BaseGitCodeClient:
|
|
|
40
41
|
repo: Optional[str] = None,
|
|
41
42
|
base_url: str = DEFAULT_BASE_URL,
|
|
42
43
|
timeout: Optional[float] = None,
|
|
44
|
+
decrypt: Optional[Callable] = None,
|
|
43
45
|
) -> None:
|
|
44
46
|
"""Store client configuration and resolve authentication."""
|
|
45
|
-
self.api_key = self._resolve_api_key(api_key)
|
|
47
|
+
self.api_key = self._resolve_api_key(api_key, decrypt)
|
|
46
48
|
self.owner = owner
|
|
47
49
|
self.repo = repo
|
|
48
50
|
self.base_url = base_url.rstrip("/")
|
|
49
51
|
self.timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
|
|
50
52
|
|
|
51
|
-
def _resolve_api_key(self, api_key: Optional[str]) -> str:
|
|
53
|
+
def _resolve_api_key(self, api_key: Optional[str], decrypt: Optional[Callable] = None) -> str:
|
|
52
54
|
"""Resolve the access token from an argument or environment variable."""
|
|
53
55
|
token = api_key or os.getenv(DEFAULT_TOKEN_ENV)
|
|
56
|
+
if callable(decrypt):
|
|
57
|
+
token = decrypt(token)
|
|
54
58
|
if not token:
|
|
55
59
|
raise GitCodeConfigurationError("No API key provided. Pass api_key=... or set GITCODE_ACCESS_TOKEN.")
|
|
56
|
-
return token
|
|
60
|
+
return str(token)
|
|
57
61
|
|
|
58
62
|
def _resolve_repo_context(
|
|
59
63
|
self,
|
|
@@ -187,6 +191,7 @@ class SyncAPIClient(BaseGitCodeClient):
|
|
|
187
191
|
:param base_url: Base URL for the GitCode REST API.
|
|
188
192
|
:param timeout: Request timeout in seconds.
|
|
189
193
|
:param http_client: Optional pre-configured ``httpx.Client`` instance.
|
|
194
|
+
:param decrypt: Optional decryption function for encrypted access token.
|
|
190
195
|
"""
|
|
191
196
|
|
|
192
197
|
def __init__(
|
|
@@ -198,9 +203,10 @@ class SyncAPIClient(BaseGitCodeClient):
|
|
|
198
203
|
base_url: str = DEFAULT_BASE_URL,
|
|
199
204
|
timeout: Optional[float] = None,
|
|
200
205
|
http_client: Optional[httpx.Client] = None,
|
|
206
|
+
decrypt: Optional[Callable] = None,
|
|
201
207
|
) -> None:
|
|
202
208
|
"""Create or reuse an ``httpx.Client`` for synchronous requests."""
|
|
203
|
-
super().__init__(api_key=api_key, owner=owner, repo=repo, base_url=base_url, timeout=timeout)
|
|
209
|
+
super().__init__(api_key=api_key, owner=owner, repo=repo, base_url=base_url, timeout=timeout, decrypt=decrypt)
|
|
204
210
|
self._owns_client = http_client is None
|
|
205
211
|
self._client = http_client or httpx.Client(timeout=self.timeout)
|
|
206
212
|
|
|
@@ -238,9 +244,8 @@ class SyncAPIClient(BaseGitCodeClient):
|
|
|
238
244
|
return self._parse_response(response, raw=raw)
|
|
239
245
|
|
|
240
246
|
def close(self) -> None:
|
|
241
|
-
"""Close the underlying HTTP client
|
|
242
|
-
|
|
243
|
-
self._client.close()
|
|
247
|
+
"""Close the underlying HTTP client."""
|
|
248
|
+
self._client.close()
|
|
244
249
|
|
|
245
250
|
def __enter__(self) -> "SyncAPIClient":
|
|
246
251
|
"""Enter a context manager and return the client instance."""
|
|
@@ -260,6 +265,7 @@ class AsyncAPIClient(BaseGitCodeClient):
|
|
|
260
265
|
:param base_url: Base URL for the GitCode REST API.
|
|
261
266
|
:param timeout: Request timeout in seconds.
|
|
262
267
|
:param http_client: Optional pre-configured ``httpx.AsyncClient`` instance.
|
|
268
|
+
:param decrypt: Optional decryption function for encrypted access token.
|
|
263
269
|
"""
|
|
264
270
|
|
|
265
271
|
def __init__(
|
|
@@ -271,9 +277,10 @@ class AsyncAPIClient(BaseGitCodeClient):
|
|
|
271
277
|
base_url: str = DEFAULT_BASE_URL,
|
|
272
278
|
timeout: Optional[float] = None,
|
|
273
279
|
http_client: Optional[httpx.AsyncClient] = None,
|
|
280
|
+
decrypt: Optional[Callable] = None,
|
|
274
281
|
) -> None:
|
|
275
282
|
"""Create or reuse an ``httpx.AsyncClient`` for asynchronous requests."""
|
|
276
|
-
super().__init__(api_key=api_key, owner=owner, repo=repo, base_url=base_url, timeout=timeout)
|
|
283
|
+
super().__init__(api_key=api_key, owner=owner, repo=repo, base_url=base_url, timeout=timeout, decrypt=decrypt)
|
|
277
284
|
self._owns_client = http_client is None
|
|
278
285
|
self._client = http_client or httpx.AsyncClient(timeout=self.timeout)
|
|
279
286
|
|
|
@@ -311,9 +318,8 @@ class AsyncAPIClient(BaseGitCodeClient):
|
|
|
311
318
|
return self._parse_response(response, raw=raw)
|
|
312
319
|
|
|
313
320
|
async def close(self) -> None:
|
|
314
|
-
"""Close the underlying async HTTP client
|
|
315
|
-
|
|
316
|
-
await self._client.aclose()
|
|
321
|
+
"""Close the underlying async HTTP client."""
|
|
322
|
+
await self._client.aclose()
|
|
317
323
|
|
|
318
324
|
async def __aenter__(self) -> "AsyncAPIClient":
|
|
319
325
|
"""Enter an async context manager and return the client instance."""
|
|
@@ -4,7 +4,7 @@ These client classes expose grouped resource helpers that mirror the
|
|
|
4
4
|
published GitCode REST API documentation.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
from typing import Optional
|
|
7
|
+
from typing import Callable, Optional
|
|
8
8
|
|
|
9
9
|
import httpx
|
|
10
10
|
|
|
@@ -54,6 +54,7 @@ class GitCode(SyncAPIClient):
|
|
|
54
54
|
:param base_url: Base URL for the GitCode REST API.
|
|
55
55
|
:param timeout: Request timeout in seconds.
|
|
56
56
|
:param http_client: Optional pre-configured ``httpx.Client`` instance.
|
|
57
|
+
:param decrypt: Optional decryption function for encrypted access token.
|
|
57
58
|
"""
|
|
58
59
|
|
|
59
60
|
repos: ReposResource
|
|
@@ -113,6 +114,7 @@ class GitCode(SyncAPIClient):
|
|
|
113
114
|
base_url: str = DEFAULT_BASE_URL,
|
|
114
115
|
timeout: Optional[float] = None,
|
|
115
116
|
http_client: Optional[httpx.Client] = None,
|
|
117
|
+
decrypt: Optional[Callable] = None,
|
|
116
118
|
) -> None:
|
|
117
119
|
"""Create a synchronous client and attach resource groups."""
|
|
118
120
|
super().__init__(
|
|
@@ -122,6 +124,7 @@ class GitCode(SyncAPIClient):
|
|
|
122
124
|
base_url=base_url,
|
|
123
125
|
timeout=timeout,
|
|
124
126
|
http_client=http_client,
|
|
127
|
+
decrypt=decrypt,
|
|
125
128
|
)
|
|
126
129
|
self.repos = ReposResource(self)
|
|
127
130
|
self.contents = RepoContentsResource(self)
|
|
@@ -153,6 +156,7 @@ class AsyncGitCode(AsyncAPIClient):
|
|
|
153
156
|
:param base_url: Base URL for the GitCode REST API.
|
|
154
157
|
:param timeout: Request timeout in seconds.
|
|
155
158
|
:param http_client: Optional pre-configured ``httpx.AsyncClient`` instance.
|
|
159
|
+
:param decrypt: Optional decryption function for encrypted access token.
|
|
156
160
|
"""
|
|
157
161
|
|
|
158
162
|
repos: AsyncReposResource
|
|
@@ -212,6 +216,7 @@ class AsyncGitCode(AsyncAPIClient):
|
|
|
212
216
|
base_url: str = DEFAULT_BASE_URL,
|
|
213
217
|
timeout: Optional[float] = None,
|
|
214
218
|
http_client: Optional[httpx.AsyncClient] = None,
|
|
219
|
+
decrypt: Optional[Callable] = None,
|
|
215
220
|
) -> None:
|
|
216
221
|
"""Create an asynchronous client and attach resource groups."""
|
|
217
222
|
super().__init__(
|
|
@@ -221,6 +226,7 @@ class AsyncGitCode(AsyncAPIClient):
|
|
|
221
226
|
base_url=base_url,
|
|
222
227
|
timeout=timeout,
|
|
223
228
|
http_client=http_client,
|
|
229
|
+
decrypt=decrypt,
|
|
224
230
|
)
|
|
225
231
|
self.repos = AsyncReposResource(self)
|
|
226
232
|
self.contents = AsyncRepoContentsResource(self)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.1.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: Easy to use Python SDK for the GitCode REST API, community-maintained.
|
|
5
5
|
Author-email: Hugo Huang <hugo@hugohuang.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,9 +27,9 @@ Dynamic: license-file
|
|
|
27
27
|
|
|
28
28
|
# GitCode-API
|
|
29
29
|
|
|
30
|
-
   ](https://pypi.org/project/gitcode-api) [](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API) [](https://pepy.tech/projects/gitcode-api)
|
|
31
31
|
|
|
32
|
-
  
|
|
32
|
+
[](https://gitcode-api.readthedocs.io) [](README.zh.md) [](README.md)
|
|
33
33
|
|
|
34
34
|
`gitcode-api` is a community-maintained Python SDK for the GitCode REST API. It provides easy-to-use synchronous and asynchronous clients, repository-scoped helpers, and lightweight response models so you can work with GitCode from Python without hand-writing raw HTTP requests.
|
|
35
35
|
|
|
@@ -57,6 +57,20 @@ Pass `api_key=` directly, or set `GITCODE_ACCESS_TOKEN` in your environment:
|
|
|
57
57
|
export GITCODE_ACCESS_TOKEN="your-token"
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
If your token is stored in encrypted form, pass `decrypt=` to decode either an
|
|
61
|
+
encrypted `api_key=` value or an encrypted `GITCODE_ACCESS_TOKEN` value before
|
|
62
|
+
the client uses it.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from gitcode_api import GitCode
|
|
66
|
+
from trusted_library import decrypt_token
|
|
67
|
+
|
|
68
|
+
client = GitCode(
|
|
69
|
+
api_key="encrypted-token",
|
|
70
|
+
decrypt=decrypt_token,
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
60
74
|
## Quick Start
|
|
61
75
|
|
|
62
76
|
### Sync client
|
|
@@ -69,40 +83,31 @@ client = GitCode(
|
|
|
69
83
|
repo="GitCode-API",
|
|
70
84
|
)
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
branches = client.branches.list(per_page=5)
|
|
86
|
+
repo = client.repos.get()
|
|
87
|
+
branches = client.branches.list(per_page=5)
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
finally:
|
|
80
|
-
client.close()
|
|
89
|
+
print(repo.full_name)
|
|
90
|
+
for branch in branches:
|
|
91
|
+
print(branch.name)
|
|
81
92
|
```
|
|
82
93
|
|
|
83
94
|
### Async client
|
|
84
95
|
|
|
85
96
|
```python
|
|
86
97
|
import asyncio
|
|
87
|
-
|
|
88
98
|
from gitcode_api import AsyncGitCode
|
|
89
99
|
|
|
90
|
-
|
|
91
100
|
async def main() -> None:
|
|
92
101
|
client = AsyncGitCode(owner="SushiNinja", repo="GitCode-API")
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
print(len(pulls))
|
|
96
|
-
finally:
|
|
97
|
-
await client.close()
|
|
98
|
-
|
|
102
|
+
pulls = await client.pulls.list(state="open", per_page=20)
|
|
103
|
+
print(len(pulls))
|
|
99
104
|
|
|
100
105
|
asyncio.run(main())
|
|
101
106
|
```
|
|
102
107
|
|
|
103
108
|
### Context managers
|
|
104
109
|
|
|
105
|
-
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`.
|
|
110
|
+
`GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`. Leaving the block calls `close()` / `await close()` on the underlying client automatically, including a custom `http_client=` you passed in.
|
|
106
111
|
|
|
107
112
|
```python
|
|
108
113
|
from gitcode_api import GitCode
|
|
@@ -114,21 +119,16 @@ with GitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
|
114
119
|
|
|
115
120
|
```python
|
|
116
121
|
import asyncio
|
|
117
|
-
|
|
118
122
|
from gitcode_api import AsyncGitCode
|
|
119
123
|
|
|
120
|
-
|
|
121
124
|
async def main() -> None:
|
|
122
125
|
async with AsyncGitCode(owner="SushiNinja", repo="GitCode-API") as client:
|
|
123
126
|
pulls = await client.pulls.list(state="open", per_page=20)
|
|
124
127
|
print(len(pulls))
|
|
125
128
|
|
|
126
|
-
|
|
127
129
|
asyncio.run(main())
|
|
128
130
|
```
|
|
129
131
|
|
|
130
|
-
If you pass a custom `http_client=`, the SDK does not close it; you still own that client’s lifecycle (for example `async with httpx.AsyncClient(...) as http:` plus `AsyncGitCode(http_client=http)`).
|
|
131
|
-
|
|
132
132
|
## Common Workflows
|
|
133
133
|
|
|
134
134
|
Create a pull request:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "gitcode-api"
|
|
3
|
-
version = "1.1.
|
|
3
|
+
version = "1.1.2"
|
|
4
4
|
description = "Easy to use Python SDK for the GitCode REST API, community-maintained."
|
|
5
5
|
keywords = ["gitcode", "git", "devops", "api", "sdk", "python", "httpx", "client"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -55,7 +55,7 @@ github = "https://github.com/Trenza1ore/GitCode-API"
|
|
|
55
55
|
default-groups = ['test']
|
|
56
56
|
|
|
57
57
|
[tool.setuptools.package-data]
|
|
58
|
-
|
|
58
|
+
gitcode_api = ["**/version.txt"]
|
|
59
59
|
|
|
60
60
|
[tool.coverage.run]
|
|
61
61
|
omit = ["tests/*"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|