安装
poetry add nonebot-adapter-github
# 或者
pip install nonebot-adapter-github
加载适配器
import nonebot
from nonebot.adapters.github import Adapter
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(Adapter)
配置
配置 APP
GITHUB_APPS='
[
{
"app_id": "123456", # GitHub App ID 必填
"private_key": [
"-----BEGIN RSA PRIVATE KEY-----",
"...", # 将私钥按行输入
"...",
"...",
"-----END RSA PRIVATE KEY-----"
], # GitHub App 私钥必填
"client_id": "123456", # OAuth App Client ID 必填,GitHub App 可选
"client_secret": "xxxxxx", # OAuth App Client Secret 必填,GitHub App 可选
"webhook_secret": "xxxxxx" # 可选
}
]'
其他配置
GITHUB_BASE_URL=https://api.github.com
GITHUB_ACCEPT_FORMAT=full+json
GITHUB_PREVIEWS=["starfox"]
使用
WebHook
URL: /github/webhooks/<app_id> (GitHub APP) / /github/webhooks/<client_id> (OAuth APP)
事件格式:
class Event(BaseModel):
id: str # 事件 ID
name: str # 事件名称
payload: Dict[str, Any] # 事件内容
to_me: bool = False # 是否 @ 了机器人或机器人昵称
具体事件类型及内容请参考 GitHub Developer
调用 API
可以直接通过 bot 调用 API,但是请注意 只能使用异步接口,参数必须是 keyword args。具体使用方法参考 githubkit。
async with bot.as_installation(installation_id=1):
resp = await bot.rest.issues.async_get(owner="owner", repo="repo", issue_number=1)
issue = resp.parsed_data
resp = await bot.async_graphql(query=query)
async for issue in bot.github.paginate(bot.rest.issues.async_list_for_repo, owner="owner", repo="repo"):
print(issue)
也可以直接使用 githubkit,但是将绕过 NoneBot 的 call api hook。
github = bot.github
开发
生成事件列表:
python -m codegen && ruff check --fix -e . && ruff format .
Metadata
Release files for nonebot-adapter-github 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_adapter_github-0.5.0.tar.gz | 33.3 kB | With provenance | Details for nonebot_adapter_github-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonebot_adapter_github-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for nonebot_adapter_github-0.5.0-py3-none-any.whl |
Total release size: 144.2 kB
Release files / nonebot_adapter_github-0.5.0.tar.gz
| Download URL | nonebot_adapter_github-0.5.0.tar.gz |
|---|---|
| Size | 33.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03ad011eea89b269ec1ce881458f1c143ee3f8d3c74d7c573d28bd35c907f26a
|
|
BLAKE2b-256 checksum How to use checksums |
8318f482d679e30f5cf4707e5ad28a95d371af10de0bffffdde633a322e4b750
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2024.
Transparency logRelease files / nonebot_adapter_github-0.5.0-py3-none-any.whl
| Download URL | nonebot_adapter_github-0.5.0-py3-none-any.whl |
|---|---|
| Size | 110.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7ec4ad910adf55309ce8212762370680998e6c8bce6a2312e855e858f83bfe1
|
|
BLAKE2b-256 checksum How to use checksums |
c8c554b5042e5eac4988c610543320ee24278da23bf7e0a754bdedf965cddb45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2024.
Transparency logSecurity for nonebot-adapter-github 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for nonebot_adapter_github-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.