githubkit 0.11.0a0__tar.gz → 0.11.0a1__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.
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/PKG-INFO +119 -17
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/README.md +115 -15
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/__init__.py +5 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/_url.py +19 -2
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/app.py +35 -16
- githubkit-0.11.0a1/githubkit/compat.py +110 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/config.py +8 -1
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/core.py +28 -3
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/github.py +9 -3
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/graphql/models.py +6 -6
- githubkit-0.11.0a1/githubkit/lazy_module.py +120 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/response.py +3 -2
- githubkit-0.11.0a1/githubkit/rest/__init__.py +14147 -0
- githubkit-0.11.0a1/githubkit/typing.py +67 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/utils.py +40 -3
- githubkit-0.11.0a1/githubkit/versions/__init__.py +19 -0
- githubkit-0.11.0a1/githubkit/versions/latest/models.py +14147 -0
- githubkit-0.11.0a1/githubkit/versions/latest/types.py +14283 -0
- githubkit-0.11.0a1/githubkit/versions/latest/webhooks.py +705 -0
- githubkit-0.11.0a1/githubkit/versions/rest.py +55 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/models/__init__.py +95086 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/rest/__init__.py +265 -0
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/actions.py +1457 -831
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/activity.py +472 -220
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/apps.py +470 -235
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/billing.py +47 -18
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/checks.py +219 -131
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/classroom.py +86 -38
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/code_scanning.py +316 -122
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/codes_of_conduct.py +29 -10
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/codespaces.py +726 -345
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/copilot.py +144 -96
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/dependabot.py +262 -155
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/dependency_graph.py +63 -34
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/emojis.py +17 -8
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/gists.py +257 -131
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/git.py +194 -114
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/gitignore.py +25 -10
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/interactions.py +135 -56
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/issues.py +913 -414
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/licenses.py +47 -16
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/markdown.py +37 -33
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/meta.py +44 -17
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/migrations.py +322 -163
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/oidc.py +34 -19
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/orgs.py +2453 -703
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/packages.py +237 -84
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/projects.py +468 -244
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/pulls.py +561 -296
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/rate_limit.py +17 -8
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/reactions.py +399 -227
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/repos.py +3297 -1565
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/search.py +141 -71
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/secret_scanning.py +164 -64
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/security_advisories.py +239 -91
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/teams.py +774 -448
- {githubkit-0.11.0a0/githubkit → githubkit-0.11.0a1/githubkit/versions/v2022_11_28}/rest/users.py +552 -266
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/types/__init__.py +74008 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/__init__.py +406 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/_namespace.py +1314 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/_types.py +395 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/branch_protection_configuration.py +45 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/branch_protection_rule.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/check_run.py +46 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/check_suite.py +43 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/code_scanning_alert.py +57 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/commit_comment.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/create.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/custom_property.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/custom_property_values.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/delete.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/dependabot_alert.py +60 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/deploy_key.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/deployment.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/deployment_protection_rule.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/deployment_review.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/deployment_status.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/discussion.py +79 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/discussion_comment.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/fork.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/github_app_authorization.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/gollum.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/installation.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/installation_repositories.py +45 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/installation_target.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/issue_comment.py +43 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/issues.py +82 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/label.py +39 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/marketplace_purchase.py +54 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/member.py +39 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/membership.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/merge_group.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/meta.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/milestone.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/org_block.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/organization.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/package.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/page_build.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/personal_access_token_request.py +51 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/ping.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/project.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/project_card.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/project_column.py +46 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/projects_v2.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/projects_v2_item.py +60 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/public.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/pull_request.py +130 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/pull_request_review.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/pull_request_review_comment.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/pull_request_review_thread.py +45 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/push.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/registry_package.py +42 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/release.py +55 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository.py +61 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository_advisory.py +45 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository_dispatch.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository_import.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository_ruleset.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/repository_vulnerability_alert.py +51 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/secret_scanning_alert.py +51 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/secret_scanning_alert_location.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/security_advisory.py +48 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/security_and_analysis.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/sponsorship.py +52 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/star.py +37 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/status.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/team.py +49 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/team_add.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/watch.py +28 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/workflow_dispatch.py +33 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/workflow_job.py +46 -0
- githubkit-0.11.0a1/githubkit/versions/v2022_11_28/webhooks/workflow_run.py +43 -0
- githubkit-0.11.0a1/githubkit/versions/webhooks.py +50 -0
- githubkit-0.11.0a1/githubkit/webhooks/__init__.py +21 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/pyproject.toml +172 -36
- githubkit-0.11.0a0/githubkit/rest/__init__.py +0 -196
- githubkit-0.11.0a0/githubkit/rest/models.py +0 -22271
- githubkit-0.11.0a0/githubkit/rest/types.py +0 -15068
- githubkit-0.11.0a0/githubkit/typing.py +0 -56
- githubkit-0.11.0a0/githubkit/webhooks/__init__.py +0 -8
- githubkit-0.11.0a0/githubkit/webhooks/models.py +0 -18290
- githubkit-0.11.0a0/githubkit/webhooks/parse.py +0 -27
- githubkit-0.11.0a0/githubkit/webhooks/types.py +0 -1171
- githubkit-0.11.0a0/githubkit/webhooks/verify.py +0 -81
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/LICENSE +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/__init__.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/action.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/base.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/oauth.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/token.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/auth/unauth.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/cache/__init__.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/cache/base.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/cache/mem_cache.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/exception.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/graphql/__init__.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/paginator.py +0 -0
- {githubkit-0.11.0a0 → githubkit-0.11.0a1}/githubkit/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: GitHubKit
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.0a1
|
|
4
4
|
Summary: GitHub SDK for Python
|
|
5
5
|
Home-page: https://github.com/yanyongyu/githubkit
|
|
6
6
|
License: MIT
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
18
|
Provides-Extra: all
|
|
18
19
|
Provides-Extra: auth
|
|
19
20
|
Provides-Extra: auth-app
|
|
@@ -21,8 +22,9 @@ Provides-Extra: auth-oauth-device
|
|
|
21
22
|
Provides-Extra: jwt
|
|
22
23
|
Requires-Dist: PyJWT[crypto] (>=2.4.0,<3.0.0) ; extra == "jwt" or extra == "auth-app" or extra == "auth" or extra == "all"
|
|
23
24
|
Requires-Dist: anyio (>=3.6.1,<4.0.0) ; extra == "auth-oauth-device" or extra == "auth" or extra == "all"
|
|
25
|
+
Requires-Dist: hishel (>=0.0.21,<0.0.22)
|
|
24
26
|
Requires-Dist: httpx (>=0.23.0,<1.0.0)
|
|
25
|
-
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
|
27
|
+
Requires-Dist: pydantic (>=2.0.0,<3.0.0,!=2.5.0,!=2.5.1)
|
|
26
28
|
Requires-Dist: typing-extensions (>=4.3.0,<5.0.0)
|
|
27
29
|
Project-URL: Documentation, https://github.com/yanyongyu/githubkit
|
|
28
30
|
Project-URL: Repository, https://github.com/yanyongyu/githubkit
|
|
@@ -178,6 +180,28 @@ from githubkit import GitHub, ActionAuthStrategy
|
|
|
178
180
|
github = GitHub(ActionAuthStrategy())
|
|
179
181
|
```
|
|
180
182
|
|
|
183
|
+
### Config
|
|
184
|
+
|
|
185
|
+
githubkit is highly configurable, you can change the default config by passing config options to `GitHub`:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from githubkit import GitHub
|
|
189
|
+
|
|
190
|
+
github = GitHub(
|
|
191
|
+
base_url="https://api.github.com/",
|
|
192
|
+
accept_format="full+json",
|
|
193
|
+
previews=["starfox"],
|
|
194
|
+
user_agent="GitHubKit/Python",
|
|
195
|
+
follow_redirects=True,
|
|
196
|
+
timeout=None,
|
|
197
|
+
http_cache=True
|
|
198
|
+
)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The `accept_format` and `previews` are used to set the default `Accept` header, you can find more details in [GitHub API docs](https://docs.github.com/en/rest/overview/media-types).
|
|
202
|
+
|
|
203
|
+
The `http_cache` option enables the http caching feature powered by [Hishel](https://hishel.com/) for HTTPX. GitHub API limits the number of requests that you can make within a specific amount of time. This feature is useful to reduce the number of requests to GitHub API and avoid hitting the rate limit.
|
|
204
|
+
|
|
181
205
|
### Calling Rest API
|
|
182
206
|
|
|
183
207
|
> APIs are fully typed. Typing in the following examples is just for reference only.
|
|
@@ -186,7 +210,7 @@ Simple sync call:
|
|
|
186
210
|
|
|
187
211
|
```python
|
|
188
212
|
from githubkit import Response
|
|
189
|
-
from githubkit.
|
|
213
|
+
from githubkit.versions.latest.models import FullRepository
|
|
190
214
|
|
|
191
215
|
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
192
216
|
repo: FullRepository = resp.parsed_data
|
|
@@ -196,7 +220,7 @@ Simple async call:
|
|
|
196
220
|
|
|
197
221
|
```python
|
|
198
222
|
from githubkit import Response
|
|
199
|
-
from githubkit.
|
|
223
|
+
from githubkit.versions.latest.models import FullRepository
|
|
200
224
|
|
|
201
225
|
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
|
|
202
226
|
repo: FullRepository = resp.parsed_data
|
|
@@ -206,7 +230,7 @@ Call API with context (reusing client):
|
|
|
206
230
|
|
|
207
231
|
```python
|
|
208
232
|
from githubkit import Response
|
|
209
|
-
from githubkit.
|
|
233
|
+
from githubkit.versions.latest.models import FullRepository
|
|
210
234
|
|
|
211
235
|
with GitHub("<your_token_here>") as github:
|
|
212
236
|
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
@@ -215,13 +239,60 @@ with GitHub("<your_token_here>") as github:
|
|
|
215
239
|
|
|
216
240
|
```python
|
|
217
241
|
from githubkit import Response
|
|
218
|
-
from githubkit.
|
|
242
|
+
from githubkit.versions.latest.models import FullRepository
|
|
219
243
|
|
|
220
244
|
async with GitHub("<your_token_here>") as github:
|
|
221
245
|
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
|
|
222
246
|
repo: FullRepository = resp.parsed_data
|
|
223
247
|
```
|
|
224
248
|
|
|
249
|
+
### Data Validation
|
|
250
|
+
|
|
251
|
+
As shown above, the response data is parsed and validated by accessing the `response.parsed_data` property. This ensures that the data type returned by the API is as expected and your code is safe to use it (with static type checking). But sometimes you may want to get the raw data returned by the API, such as when the schema is not correct. You can use the `response.text` property or `response.json()` method to get the raw data:
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from typing import Any, Dict
|
|
255
|
+
from githubkit import Response
|
|
256
|
+
|
|
257
|
+
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
258
|
+
repo: Dict[str, Any] = resp.json()
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Rest API Versioning
|
|
262
|
+
|
|
263
|
+
> APIs are fully typed. Different versions of APIs are typed separately.
|
|
264
|
+
|
|
265
|
+
githubkit supports all versions of GitHub API, you can switch between versions as follows:
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
github.rest("2022-11-28").repos.get(owner="owner", repo="repo")
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The models of versions can be imported from `githubkit.versions.<version>.models`, for example:
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
from githubkit.versions.v2022_11_28.models import FullRepository
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Specially, the `latest` version is always linked to the latest version of GitHub API:
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
from githubkit.versions.latest.models import FullRepository
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
> [!NOTE]
|
|
284
|
+
> For backward compatibility, the `githubkit.rest` module is linked to the models of `latest` version by default.
|
|
285
|
+
>
|
|
286
|
+
> ```python
|
|
287
|
+
> from githubkit.rest import FullRepository
|
|
288
|
+
> ```
|
|
289
|
+
|
|
290
|
+
You can also get the latest version name of GitHub API and all versions mapping of GitHub API:
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
from githubkit.versions import LATEST_VERSION, VERSIONS
|
|
294
|
+
```
|
|
295
|
+
|
|
225
296
|
### Pagination
|
|
226
297
|
|
|
227
298
|
Pagination type checking is also supported:
|
|
@@ -229,7 +300,7 @@ Pagination type checking is also supported:
|
|
|
229
300
|
> Typing is tested with Pylance (Pyright).
|
|
230
301
|
|
|
231
302
|
```python
|
|
232
|
-
from githubkit.
|
|
303
|
+
from githubkit.versions.latest.models import Issue
|
|
233
304
|
|
|
234
305
|
for issue in github.paginate(
|
|
235
306
|
github.rest.issues.list_for_repo, owner="owner", repo="repo", state="open"
|
|
@@ -239,7 +310,7 @@ for issue in github.paginate(
|
|
|
239
310
|
```
|
|
240
311
|
|
|
241
312
|
```python
|
|
242
|
-
from githubkit.
|
|
313
|
+
from githubkit.versions.latest.models import Issue
|
|
243
314
|
|
|
244
315
|
async for issue in github.paginate(
|
|
245
316
|
github.rest.issues.async_list_for_repo, owner="owner", repo="repo", state="open"
|
|
@@ -271,11 +342,13 @@ data: Dict[str, Any] = github.graphql(query, variables={"foo": "bar"})
|
|
|
271
342
|
Simple async call:
|
|
272
343
|
|
|
273
344
|
```python
|
|
274
|
-
data: Dict[str, Any] = github.async_graphql(query, variables={"foo": "bar"})
|
|
345
|
+
data: Dict[str, Any] = await github.async_graphql(query, variables={"foo": "bar"})
|
|
275
346
|
```
|
|
276
347
|
|
|
277
348
|
### Webhook Verification
|
|
278
349
|
|
|
350
|
+
> `githubkit.webhooks` module contains some shortcut functions to help you verify and parse webhook payload.
|
|
351
|
+
|
|
279
352
|
Simple webhook payload verification:
|
|
280
353
|
|
|
281
354
|
```python
|
|
@@ -294,29 +367,41 @@ signature: str = sign(secret, payload, method="sha256")
|
|
|
294
367
|
|
|
295
368
|
### Webhook Parsing
|
|
296
369
|
|
|
370
|
+
> `githubkit.webhooks` module contains some shortcut functions to help you verify and parse webhook payload.
|
|
371
|
+
|
|
297
372
|
Parse the payload with event name:
|
|
298
373
|
|
|
299
374
|
```python
|
|
300
|
-
from githubkit.webhooks import parse
|
|
375
|
+
from githubkit.webhooks import parse
|
|
301
376
|
|
|
302
|
-
event
|
|
377
|
+
event = parse(request.headers["X-GitHub-Event"], request.body)
|
|
303
378
|
```
|
|
304
379
|
|
|
305
|
-
Parse the payload without event name (may cost longer time):
|
|
380
|
+
(NOT RECOMMENDED) Parse the payload without event name (may cost longer time and more memory):
|
|
306
381
|
|
|
307
382
|
```python
|
|
308
|
-
from githubkit.webhooks import parse_without_name
|
|
383
|
+
from githubkit.webhooks import parse_without_name
|
|
309
384
|
|
|
310
|
-
event
|
|
385
|
+
event = parse_without_name(request.body)
|
|
311
386
|
```
|
|
312
387
|
|
|
313
388
|
Parse dict like payload:
|
|
314
389
|
|
|
315
390
|
```python
|
|
316
|
-
from githubkit.webhooks import parse_obj, parse_obj_without_name
|
|
391
|
+
from githubkit.webhooks import parse_obj, parse_obj_without_name
|
|
392
|
+
|
|
393
|
+
event = parse_obj(request.headers["X-GitHub-Event"], request.json())
|
|
394
|
+
event = parse_obj_without_name(request.json()) # NOT RECOMMENDED
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
The `parse` and `parse_obj` function supports type overload, if you provide static value for the `event_name` parameter, the return type will be inferred automatically.
|
|
398
|
+
|
|
399
|
+
Webhook also supports versioning, you can switch between versions as follows:
|
|
400
|
+
|
|
401
|
+
```python
|
|
402
|
+
from githubkit import GitHub
|
|
317
403
|
|
|
318
|
-
event
|
|
319
|
-
event: WebhookEvent = parse_obj_without_name(request.json())
|
|
404
|
+
event = GitHub.webhooks("2022-11-28").parse(request.headers["X-GitHub-Event"], request.body)
|
|
320
405
|
```
|
|
321
406
|
|
|
322
407
|
### Switch between AuthStrategy
|
|
@@ -351,7 +436,24 @@ Open in Codespaces (Dev Container):
|
|
|
351
436
|
|
|
352
437
|
Generate latest models and apis:
|
|
353
438
|
|
|
439
|
+
> [!WARNING]
|
|
440
|
+
> This may use a lot of memory (**16G+** RAM) and take a long time.
|
|
441
|
+
|
|
354
442
|
```bash
|
|
355
443
|
python -m codegen && isort . && black .
|
|
356
444
|
```
|
|
357
445
|
|
|
446
|
+
Run tests:
|
|
447
|
+
|
|
448
|
+
```bash
|
|
449
|
+
pytest -n auto tests
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Contributors
|
|
453
|
+
|
|
454
|
+
Thanks to the following people who have contributed to this project:
|
|
455
|
+
|
|
456
|
+
<a href="https://github.com/yanyongyu/githubkit/graphs/contributors">
|
|
457
|
+
<img src="https://contrib.rocks/image?repo=yanyongyu/githubkit&max=1000" alt="contributors" />
|
|
458
|
+
</a>
|
|
459
|
+
|
|
@@ -148,6 +148,28 @@ from githubkit import GitHub, ActionAuthStrategy
|
|
|
148
148
|
github = GitHub(ActionAuthStrategy())
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
### Config
|
|
152
|
+
|
|
153
|
+
githubkit is highly configurable, you can change the default config by passing config options to `GitHub`:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from githubkit import GitHub
|
|
157
|
+
|
|
158
|
+
github = GitHub(
|
|
159
|
+
base_url="https://api.github.com/",
|
|
160
|
+
accept_format="full+json",
|
|
161
|
+
previews=["starfox"],
|
|
162
|
+
user_agent="GitHubKit/Python",
|
|
163
|
+
follow_redirects=True,
|
|
164
|
+
timeout=None,
|
|
165
|
+
http_cache=True
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The `accept_format` and `previews` are used to set the default `Accept` header, you can find more details in [GitHub API docs](https://docs.github.com/en/rest/overview/media-types).
|
|
170
|
+
|
|
171
|
+
The `http_cache` option enables the http caching feature powered by [Hishel](https://hishel.com/) for HTTPX. GitHub API limits the number of requests that you can make within a specific amount of time. This feature is useful to reduce the number of requests to GitHub API and avoid hitting the rate limit.
|
|
172
|
+
|
|
151
173
|
### Calling Rest API
|
|
152
174
|
|
|
153
175
|
> APIs are fully typed. Typing in the following examples is just for reference only.
|
|
@@ -156,7 +178,7 @@ Simple sync call:
|
|
|
156
178
|
|
|
157
179
|
```python
|
|
158
180
|
from githubkit import Response
|
|
159
|
-
from githubkit.
|
|
181
|
+
from githubkit.versions.latest.models import FullRepository
|
|
160
182
|
|
|
161
183
|
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
162
184
|
repo: FullRepository = resp.parsed_data
|
|
@@ -166,7 +188,7 @@ Simple async call:
|
|
|
166
188
|
|
|
167
189
|
```python
|
|
168
190
|
from githubkit import Response
|
|
169
|
-
from githubkit.
|
|
191
|
+
from githubkit.versions.latest.models import FullRepository
|
|
170
192
|
|
|
171
193
|
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
|
|
172
194
|
repo: FullRepository = resp.parsed_data
|
|
@@ -176,7 +198,7 @@ Call API with context (reusing client):
|
|
|
176
198
|
|
|
177
199
|
```python
|
|
178
200
|
from githubkit import Response
|
|
179
|
-
from githubkit.
|
|
201
|
+
from githubkit.versions.latest.models import FullRepository
|
|
180
202
|
|
|
181
203
|
with GitHub("<your_token_here>") as github:
|
|
182
204
|
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
@@ -185,13 +207,60 @@ with GitHub("<your_token_here>") as github:
|
|
|
185
207
|
|
|
186
208
|
```python
|
|
187
209
|
from githubkit import Response
|
|
188
|
-
from githubkit.
|
|
210
|
+
from githubkit.versions.latest.models import FullRepository
|
|
189
211
|
|
|
190
212
|
async with GitHub("<your_token_here>") as github:
|
|
191
213
|
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
|
|
192
214
|
repo: FullRepository = resp.parsed_data
|
|
193
215
|
```
|
|
194
216
|
|
|
217
|
+
### Data Validation
|
|
218
|
+
|
|
219
|
+
As shown above, the response data is parsed and validated by accessing the `response.parsed_data` property. This ensures that the data type returned by the API is as expected and your code is safe to use it (with static type checking). But sometimes you may want to get the raw data returned by the API, such as when the schema is not correct. You can use the `response.text` property or `response.json()` method to get the raw data:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from typing import Any, Dict
|
|
223
|
+
from githubkit import Response
|
|
224
|
+
|
|
225
|
+
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
|
|
226
|
+
repo: Dict[str, Any] = resp.json()
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Rest API Versioning
|
|
230
|
+
|
|
231
|
+
> APIs are fully typed. Different versions of APIs are typed separately.
|
|
232
|
+
|
|
233
|
+
githubkit supports all versions of GitHub API, you can switch between versions as follows:
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
github.rest("2022-11-28").repos.get(owner="owner", repo="repo")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The models of versions can be imported from `githubkit.versions.<version>.models`, for example:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from githubkit.versions.v2022_11_28.models import FullRepository
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Specially, the `latest` version is always linked to the latest version of GitHub API:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from githubkit.versions.latest.models import FullRepository
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
> [!NOTE]
|
|
252
|
+
> For backward compatibility, the `githubkit.rest` module is linked to the models of `latest` version by default.
|
|
253
|
+
>
|
|
254
|
+
> ```python
|
|
255
|
+
> from githubkit.rest import FullRepository
|
|
256
|
+
> ```
|
|
257
|
+
|
|
258
|
+
You can also get the latest version name of GitHub API and all versions mapping of GitHub API:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
from githubkit.versions import LATEST_VERSION, VERSIONS
|
|
262
|
+
```
|
|
263
|
+
|
|
195
264
|
### Pagination
|
|
196
265
|
|
|
197
266
|
Pagination type checking is also supported:
|
|
@@ -199,7 +268,7 @@ Pagination type checking is also supported:
|
|
|
199
268
|
> Typing is tested with Pylance (Pyright).
|
|
200
269
|
|
|
201
270
|
```python
|
|
202
|
-
from githubkit.
|
|
271
|
+
from githubkit.versions.latest.models import Issue
|
|
203
272
|
|
|
204
273
|
for issue in github.paginate(
|
|
205
274
|
github.rest.issues.list_for_repo, owner="owner", repo="repo", state="open"
|
|
@@ -209,7 +278,7 @@ for issue in github.paginate(
|
|
|
209
278
|
```
|
|
210
279
|
|
|
211
280
|
```python
|
|
212
|
-
from githubkit.
|
|
281
|
+
from githubkit.versions.latest.models import Issue
|
|
213
282
|
|
|
214
283
|
async for issue in github.paginate(
|
|
215
284
|
github.rest.issues.async_list_for_repo, owner="owner", repo="repo", state="open"
|
|
@@ -241,11 +310,13 @@ data: Dict[str, Any] = github.graphql(query, variables={"foo": "bar"})
|
|
|
241
310
|
Simple async call:
|
|
242
311
|
|
|
243
312
|
```python
|
|
244
|
-
data: Dict[str, Any] = github.async_graphql(query, variables={"foo": "bar"})
|
|
313
|
+
data: Dict[str, Any] = await github.async_graphql(query, variables={"foo": "bar"})
|
|
245
314
|
```
|
|
246
315
|
|
|
247
316
|
### Webhook Verification
|
|
248
317
|
|
|
318
|
+
> `githubkit.webhooks` module contains some shortcut functions to help you verify and parse webhook payload.
|
|
319
|
+
|
|
249
320
|
Simple webhook payload verification:
|
|
250
321
|
|
|
251
322
|
```python
|
|
@@ -264,29 +335,41 @@ signature: str = sign(secret, payload, method="sha256")
|
|
|
264
335
|
|
|
265
336
|
### Webhook Parsing
|
|
266
337
|
|
|
338
|
+
> `githubkit.webhooks` module contains some shortcut functions to help you verify and parse webhook payload.
|
|
339
|
+
|
|
267
340
|
Parse the payload with event name:
|
|
268
341
|
|
|
269
342
|
```python
|
|
270
|
-
from githubkit.webhooks import parse
|
|
343
|
+
from githubkit.webhooks import parse
|
|
271
344
|
|
|
272
|
-
event
|
|
345
|
+
event = parse(request.headers["X-GitHub-Event"], request.body)
|
|
273
346
|
```
|
|
274
347
|
|
|
275
|
-
Parse the payload without event name (may cost longer time):
|
|
348
|
+
(NOT RECOMMENDED) Parse the payload without event name (may cost longer time and more memory):
|
|
276
349
|
|
|
277
350
|
```python
|
|
278
|
-
from githubkit.webhooks import parse_without_name
|
|
351
|
+
from githubkit.webhooks import parse_without_name
|
|
279
352
|
|
|
280
|
-
event
|
|
353
|
+
event = parse_without_name(request.body)
|
|
281
354
|
```
|
|
282
355
|
|
|
283
356
|
Parse dict like payload:
|
|
284
357
|
|
|
285
358
|
```python
|
|
286
|
-
from githubkit.webhooks import parse_obj, parse_obj_without_name
|
|
359
|
+
from githubkit.webhooks import parse_obj, parse_obj_without_name
|
|
360
|
+
|
|
361
|
+
event = parse_obj(request.headers["X-GitHub-Event"], request.json())
|
|
362
|
+
event = parse_obj_without_name(request.json()) # NOT RECOMMENDED
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
The `parse` and `parse_obj` function supports type overload, if you provide static value for the `event_name` parameter, the return type will be inferred automatically.
|
|
366
|
+
|
|
367
|
+
Webhook also supports versioning, you can switch between versions as follows:
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
from githubkit import GitHub
|
|
287
371
|
|
|
288
|
-
event
|
|
289
|
-
event: WebhookEvent = parse_obj_without_name(request.json())
|
|
372
|
+
event = GitHub.webhooks("2022-11-28").parse(request.headers["X-GitHub-Event"], request.body)
|
|
290
373
|
```
|
|
291
374
|
|
|
292
375
|
### Switch between AuthStrategy
|
|
@@ -321,6 +404,23 @@ Open in Codespaces (Dev Container):
|
|
|
321
404
|
|
|
322
405
|
Generate latest models and apis:
|
|
323
406
|
|
|
407
|
+
> [!WARNING]
|
|
408
|
+
> This may use a lot of memory (**16G+** RAM) and take a long time.
|
|
409
|
+
|
|
324
410
|
```bash
|
|
325
411
|
python -m codegen && isort . && black .
|
|
326
412
|
```
|
|
413
|
+
|
|
414
|
+
Run tests:
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
pytest -n auto tests
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## Contributors
|
|
421
|
+
|
|
422
|
+
Thanks to the following people who have contributed to this project:
|
|
423
|
+
|
|
424
|
+
<a href="https://github.com/yanyongyu/githubkit/graphs/contributors">
|
|
425
|
+
<img src="https://contrib.rocks/image?repo=yanyongyu/githubkit&max=1000" alt="contributors" />
|
|
426
|
+
</a>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
from . import lazy_module
|
|
2
|
+
|
|
3
|
+
lazy_module.apply()
|
|
4
|
+
|
|
1
5
|
from .config import Config as Config
|
|
2
6
|
from .github import GitHub as GitHub
|
|
3
7
|
from .core import GitHubCore as GitHubCore
|
|
4
8
|
from .response import Response as Response
|
|
5
9
|
from .paginator import Paginator as Paginator
|
|
10
|
+
from .compat import GitHubModel as GitHubModel
|
|
6
11
|
from .auth import AppAuthStrategy as AppAuthStrategy
|
|
7
12
|
from .auth import BaseAuthStrategy as BaseAuthStrategy
|
|
8
13
|
from .auth import TokenAuthStrategy as TokenAuthStrategy
|
|
@@ -26,21 +26,38 @@ APP_ROUTES = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
BYPASS_REGEX = re.compile(r"/login/(oauth/access_token|device/code)$")
|
|
29
|
-
|
|
29
|
+
"""Regex to match routes that should bypass auth.
|
|
30
|
+
|
|
31
|
+
See: https://github.com/octokit/auth-oauth-user.js/blob/b8b1141b21f285027e36a4a1670163e4db51d30f/src/hook.ts#L44
|
|
32
|
+
"""
|
|
33
|
+
APP_AUTH_REGEX = re.compile(rf"^(?:{'|'.join(APP_ROUTES)})$", re.I)
|
|
34
|
+
"""Regex to match app authentication routes.
|
|
35
|
+
|
|
36
|
+
See: https://github.com/octokit/auth-app.js/blob/c0068e06081a5d930799285a7c79c9c948b676b6/src/requires-app-auth.ts#L45
|
|
37
|
+
"""
|
|
30
38
|
BASIC_AUTH_REGEX = re.compile(r"/applications/[^/]+/(token|grant)s?")
|
|
39
|
+
"""Regex to match basic authentication routes.
|
|
40
|
+
|
|
41
|
+
See: https://github.com/octokit/auth-oauth-user.js/blob/b8b1141b21f285027e36a4a1670163e4db51d30f/src/requires-basic-auth.ts#L17
|
|
42
|
+
"""
|
|
31
43
|
OAUTH_BASE_REGEX = re.compile(r"^https://(api\.)?github\.com/?$")
|
|
32
44
|
|
|
33
45
|
|
|
34
46
|
def require_bypass(url: httpx.URL) -> bool:
|
|
35
|
-
|
|
47
|
+
"""Check if the request should bypass auth."""
|
|
36
48
|
return bool(BYPASS_REGEX.search(url.path))
|
|
37
49
|
|
|
38
50
|
|
|
39
51
|
def require_app_auth(url: httpx.URL) -> bool:
|
|
52
|
+
"""Check if the request should use app authentication.
|
|
53
|
+
|
|
54
|
+
Note: the input url must remove the base url first.
|
|
55
|
+
"""
|
|
40
56
|
return bool(APP_AUTH_REGEX.search(url.path))
|
|
41
57
|
|
|
42
58
|
|
|
43
59
|
def require_basic_auth(url: httpx.URL) -> bool:
|
|
60
|
+
"""Check if the request should use basic authentication."""
|
|
44
61
|
return bool(BASIC_AUTH_REGEX.search(url.path))
|
|
45
62
|
|
|
46
63
|
|
|
@@ -7,12 +7,7 @@ import httpx
|
|
|
7
7
|
from githubkit.exception import AuthCredentialError
|
|
8
8
|
from githubkit.cache import DEFAULT_CACHE, BaseCache
|
|
9
9
|
from githubkit.utils import UNSET, Unset, exclude_unset
|
|
10
|
-
from githubkit.
|
|
11
|
-
BasicError,
|
|
12
|
-
ValidationError,
|
|
13
|
-
InstallationToken,
|
|
14
|
-
AppInstallationsInstallationIdAccessTokensPostBody,
|
|
15
|
-
)
|
|
10
|
+
from githubkit.compat import model_dump, type_validate_python
|
|
16
11
|
|
|
17
12
|
from .base import BaseAuthStrategy
|
|
18
13
|
from .oauth import OAuthAppAuthStrategy
|
|
@@ -25,7 +20,8 @@ except ImportError:
|
|
|
25
20
|
|
|
26
21
|
if TYPE_CHECKING:
|
|
27
22
|
from githubkit import Response, GitHubCore
|
|
28
|
-
from githubkit.
|
|
23
|
+
from githubkit.versions.latest.models import InstallationToken
|
|
24
|
+
from githubkit.versions.latest.types import AppPermissionsType
|
|
29
25
|
|
|
30
26
|
|
|
31
27
|
@dataclass
|
|
@@ -49,6 +45,16 @@ class AppAuth(httpx.Auth):
|
|
|
49
45
|
"{installation_id}:{permissions}:{repositories}:{repository_ids}"
|
|
50
46
|
)
|
|
51
47
|
|
|
48
|
+
def _get_api_route(self, url: httpx.URL) -> httpx.URL:
|
|
49
|
+
"""Get the api route (path only) for the given url."""
|
|
50
|
+
base_url_path = self.github.config.base_url.path
|
|
51
|
+
if (path := url.path).startswith(base_url_path):
|
|
52
|
+
path = path[len(base_url_path) :]
|
|
53
|
+
# add leading slash
|
|
54
|
+
if not path.startswith("/"):
|
|
55
|
+
path = "/" + path
|
|
56
|
+
return httpx.URL(path=path)
|
|
57
|
+
|
|
52
58
|
def _create_jwt(self) -> str:
|
|
53
59
|
"""Create a JWT authenticating as GitHub APP.
|
|
54
60
|
|
|
@@ -80,6 +86,10 @@ class AppAuth(httpx.Auth):
|
|
|
80
86
|
return token
|
|
81
87
|
|
|
82
88
|
def _build_installation_auth_request(self) -> httpx.Request:
|
|
89
|
+
from githubkit.versions.latest.models import (
|
|
90
|
+
AppInstallationsInstallationIdAccessTokensPostBody,
|
|
91
|
+
)
|
|
92
|
+
|
|
83
93
|
if self.installation_id is UNSET:
|
|
84
94
|
raise AuthCredentialError(
|
|
85
95
|
"GitHub APP installation_id must be provided "
|
|
@@ -91,13 +101,16 @@ class AppAuth(httpx.Auth):
|
|
|
91
101
|
raw_path=base_url.raw_path
|
|
92
102
|
+ f"app/installations/{self.installation_id}/access_tokens".encode("ascii")
|
|
93
103
|
)
|
|
94
|
-
body =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
body = model_dump(
|
|
105
|
+
type_validate_python(
|
|
106
|
+
AppInstallationsInstallationIdAccessTokensPostBody,
|
|
107
|
+
{
|
|
108
|
+
"repositories": self.repositories,
|
|
109
|
+
"repository_ids": self.repository_ids,
|
|
110
|
+
"permissions": self.permissions,
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
)
|
|
101
114
|
return httpx.Request(
|
|
102
115
|
"POST",
|
|
103
116
|
url,
|
|
@@ -111,6 +124,12 @@ class AppAuth(httpx.Auth):
|
|
|
111
124
|
def _parse_installation_auth_response(
|
|
112
125
|
self, response: httpx.Response
|
|
113
126
|
) -> "Response[InstallationToken]":
|
|
127
|
+
from githubkit.versions.latest.models import (
|
|
128
|
+
BasicError,
|
|
129
|
+
ValidationError,
|
|
130
|
+
InstallationToken,
|
|
131
|
+
)
|
|
132
|
+
|
|
114
133
|
return self.github._check(
|
|
115
134
|
response,
|
|
116
135
|
response_model=InstallationToken,
|
|
@@ -150,7 +169,7 @@ class AppAuth(httpx.Auth):
|
|
|
150
169
|
if require_bypass(request.url):
|
|
151
170
|
yield request
|
|
152
171
|
return
|
|
153
|
-
if require_app_auth(request.url):
|
|
172
|
+
if require_app_auth(self._get_api_route(request.url)):
|
|
154
173
|
request.headers["Authorization"] = f"Bearer {self.get_jwt()}"
|
|
155
174
|
yield request
|
|
156
175
|
return
|
|
@@ -186,7 +205,7 @@ class AppAuth(httpx.Auth):
|
|
|
186
205
|
if require_bypass(request.url):
|
|
187
206
|
yield request
|
|
188
207
|
return
|
|
189
|
-
if require_app_auth(request.url):
|
|
208
|
+
if require_app_auth(self._get_api_route(request.url)):
|
|
190
209
|
request.headers["Authorization"] = f"Bearer {await self.aget_jwt()}"
|
|
191
210
|
yield request
|
|
192
211
|
return
|