{"id":20390251,"url":"https://github.com/nonebot/adapter-github","last_synced_at":"2025-04-12T11:21:14.658Z","repository":{"id":50723100,"uuid":"519955202","full_name":"nonebot/adapter-github","owner":"nonebot","description":"GitHub adapter for nonebot2","archived":false,"fork":false,"pushed_at":"2024-09-03T08:04:59.000Z","size":407,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T23:36:20.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nonebot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"nonebot","custom":["https://afdian.com/@nonebot"]}},"created_at":"2022-08-01T03:48:44.000Z","updated_at":"2024-09-03T08:04:52.000Z","dependencies_parsed_at":"2023-11-13T05:34:33.584Z","dependency_job_id":"696c5f76-5d86-45a4-b87f-1e15f589c10a","html_url":"https://github.com/nonebot/adapter-github","commit_stats":{"total_commits":81,"total_committers":5,"mean_commits":16.2,"dds":"0.28395061728395066","last_synced_commit":"3e92bb8ec9ad6ce82f6d23a899c76fe3006c7f01"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonebot%2Fadapter-github","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonebot%2Fadapter-github/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonebot%2Fadapter-github/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonebot%2Fadapter-github/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nonebot","download_url":"https://codeload.github.com/nonebot/adapter-github/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248558129,"owners_count":21124223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T03:23:52.555Z","updated_at":"2025-04-12T11:21:14.651Z","avatar_url":"https://github.com/nonebot.png","language":"Python","funding_links":["https://opencollective.com/nonebot","https://afdian.com/@nonebot"],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable-next-line MD041 --\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://nonebot.dev/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/nonebot/adapter-github/master/assets/logo.png\" width=\"200\" height=\"200\" alt=\"nonebot\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# NoneBot-Adapter-GitHub\n\n\u003c!-- markdownlint-capture --\u003e\n\u003c!-- markdownlint-disable MD036 --\u003e\n\n_✨ GitHub 协议适配 ✨_\n\n\u003c!-- markdownlint-restore --\u003e\n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://raw.githubusercontent.com/nonebot/adapter-github/master/LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/nonebot/adapter-github\" alt=\"license\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pypi.python.org/pypi/nonebot-adapter-github\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/nonebot-adapter-github\" alt=\"pypi\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/python-3.9+-blue\" alt=\"python\"\u003e\n  \u003ca href=\"https://results.pre-commit.ci/latest/github/nonebot/adapter-github/master\"\u003e\n    \u003cimg src=\"https://results.pre-commit.ci/badge/github/nonebot/adapter-github/master.svg\" alt=\"pre-commit\"/\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n  \u003ca href=\"https://jq.qq.com/?_wv=1027\u0026k=5OFifDh\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=flat-square\" alt=\"QQ Chat Group\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://qun.qq.com/qqweb/qunpro/share?_wv=3\u0026_wwv=128\u0026appChannel=share\u0026inviteCode=7b4a3\u0026appChannel=share\u0026businessType=9\u0026from=246610\u0026biz=ka\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/QQ%E9%A2%91%E9%81%93-NoneBot-5492ff?style=flat-square\" alt=\"QQ Channel\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://t.me/botuniverse\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/telegram-botuniverse-blue?style=flat-square\" alt=\"Telegram Channel\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://discord.gg/VKtE6Gdc4h\"\u003e\n    \u003cimg src=\"https://discordapp.com/api/guilds/847819937858584596/widget.png?style=shield\" alt=\"Discord Server\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## 安装\n\n```bash\npoetry add nonebot-adapter-github\n# 或者\npip install nonebot-adapter-github\n```\n\n## 加载适配器\n\n```python\nimport nonebot\nfrom nonebot.adapters.github import Adapter\n\nnonebot.init()\n\ndriver = nonebot.get_driver()\ndriver.register_adapter(Adapter)\n```\n\n## 配置\n\n### 配置 APP\n\n```dotenv\nGITHUB_APPS='\n[\n  {\n    \"app_id\": \"123456\",  # GitHub App ID 必填\n    \"private_key\": [\n      \"-----BEGIN RSA PRIVATE KEY-----\",\n      \"...\",  # 将私钥按行输入\n      \"...\",\n      \"...\",\n      \"-----END RSA PRIVATE KEY-----\"\n    ],  # GitHub App 私钥必填\n    \"client_id\": \"123456\",  # OAuth App Client ID 必填，GitHub App 可选\n    \"client_secret\": \"xxxxxx\",  # OAuth App Client Secret 必填，GitHub App 可选\n    \"webhook_secret\": \"xxxxxx\"  # 可选\n  }\n]'\n```\n\n### 其他配置\n\n```dotenv\nGITHUB_BASE_URL=https://api.github.com\nGITHUB_ACCEPT_FORMAT=full+json\nGITHUB_PREVIEWS=[\"starfox\"]\n```\n\n## 使用\n\n### WebHook\n\nURL: `/github/webhooks/\u003capp_id\u003e` (GitHub APP) / `/github/webhooks/\u003cclient_id\u003e` (OAuth APP)\n\n事件格式:\n\n```python\nclass Event(BaseModel):\n    id: str  # 事件 ID\n    name: str  # 事件名称\n    payload: Dict[str, Any]  # 事件内容\n\n    to_me: bool = False  # 是否 @ 了机器人或机器人昵称\n```\n\n具体事件类型及内容请参考 [GitHub Developer](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)\n\n### 调用 API\n\n可以直接通过 bot 调用 API，但是请注意 **只能使用异步接口，参数必须是 keyword args**。具体使用方法参考 [githubkit](https://github.com/yanyongyu/githubkit)。\n\n```python\nasync with bot.as_installation(installation_id=1):\n    resp = await bot.rest.issues.async_get(owner=\"owner\", repo=\"repo\", issue_number=1)\n    issue = resp.parsed_data\n\n    resp = await bot.async_graphql(query=query)\n\n    async for issue in bot.github.paginate(bot.rest.issues.async_list_for_repo, owner=\"owner\", repo=\"repo\"):\n        print(issue)\n```\n\n也可以直接使用 `githubkit`，但是将绕过 NoneBot 的 `call api hook`。\n\n```python\ngithub = bot.github\n```\n\n## 开发\n\n生成事件列表：\n\n```bash\npython -m codegen \u0026\u0026 ruff check --fix -e . \u0026\u0026 ruff format .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonebot%2Fadapter-github","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnonebot%2Fadapter-github","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonebot%2Fadapter-github/lists"}