nonebot-adapter-github


Namenonebot-adapter-github JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/nonebot/adapter-github
SummaryGitHub adapter for nonebot2
upload_time2024-02-17 15:37:38
maintainer
docs_urlNone
authoryanyongyu
requires_python>=3.8,<4.0
licenseMIT
keywords bot github webhook
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- markdownlint-disable-next-line MD041 -->
<p align="center">
  <a href="https://nonebot.dev/"><img src="https://raw.githubusercontent.com/nonebot/adapter-github/master/assets/logo.png" width="200" height="200" alt="nonebot"></a>
</p>

<div align="center">

# NoneBot-Adapter-GitHub

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD036 -->

_✨ GitHub 协议适配 ✨_

<!-- markdownlint-restore -->

</div>

<p align="center">
  <a href="https://raw.githubusercontent.com/nonebot/adapter-github/master/LICENSE">
    <img src="https://img.shields.io/github/license/nonebot/adapter-github" alt="license">
  </a>
  <a href="https://pypi.python.org/pypi/nonebot-adapter-github">
    <img src="https://img.shields.io/pypi/v/nonebot-adapter-github" alt="pypi">
  </a>
  <img src="https://img.shields.io/badge/python-3.8+-blue" alt="python">
  <a href="https://results.pre-commit.ci/latest/github/nonebot/adapter-github/master">
    <img src="https://results.pre-commit.ci/badge/github/nonebot/adapter-github/master.svg" />
  </a>
  <br />
  <a href="https://jq.qq.com/?_wv=1027&k=5OFifDh">
    <img src="https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=flat-square" alt="QQ Chat Group">
  </a>
  <a href="https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&appChannel=share&inviteCode=7b4a3&appChannel=share&businessType=9&from=246610&biz=ka">
    <img src="https://img.shields.io/badge/QQ%E9%A2%91%E9%81%93-NoneBot-5492ff?style=flat-square" alt="QQ Channel">
  </a>
  <a href="https://t.me/botuniverse">
    <img src="https://img.shields.io/badge/telegram-botuniverse-blue?style=flat-square" alt="Telegram Channel">
  </a>
  <a href="https://discord.gg/VKtE6Gdc4h">
    <img src="https://discordapp.com/api/guilds/847819937858584596/widget.png?style=shield" alt="Discord Server">
  </a>
</p>

## 安装

```bash
poetry add nonebot-adapter-github
# 或者
pip install nonebot-adapter-github
```

## 加载适配器

```python
import nonebot
from nonebot.adapters.github import Adapter

nonebot.init()

driver = nonebot.get_driver()
driver.register_adapter(Adapter)
```

## 配置

### 配置 APP

```dotenv
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"  # 可选
  }
]'
```

### 其他配置

```dotenv
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)

事件格式:

```python
class Event(BaseModel):
    id: str  # 事件 ID
    name: str  # 事件名称
    payload: Dict[str, Any]  # 事件内容

    to_me: bool = False  # 是否 @ 了机器人或机器人昵称
```

具体事件类型及内容请参考 [GitHub Developer](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)

### 调用 API

可以直接通过 bot 调用 API,但是请注意 **只能使用异步接口,参数必须是 keyword args**。具体使用方法参考 [githubkit](https://github.com/yanyongyu/githubkit)。

```python
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`。

```python
github = bot.github
```

## 开发

生成事件列表:

```bash
python -m codegen && ruff check --fix -e . && isort . && black .
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nonebot/adapter-github",
    "name": "nonebot-adapter-github",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "bot,github,webhook",
    "author": "yanyongyu",
    "author_email": "yyy@nonebot.dev",
    "download_url": "https://files.pythonhosted.org/packages/8d/e5/d6983ff7fe2b9700b012261a52bfbc62670c19768a7d52f2350da4b2225f/nonebot_adapter_github-0.4.1.tar.gz",
    "platform": null,
    "description": "<!-- markdownlint-disable-next-line MD041 -->\n<p align=\"center\">\n  <a href=\"https://nonebot.dev/\"><img src=\"https://raw.githubusercontent.com/nonebot/adapter-github/master/assets/logo.png\" width=\"200\" height=\"200\" alt=\"nonebot\"></a>\n</p>\n\n<div align=\"center\">\n\n# NoneBot-Adapter-GitHub\n\n<!-- markdownlint-capture -->\n<!-- markdownlint-disable MD036 -->\n\n_\u2728 GitHub \u534f\u8bae\u9002\u914d \u2728_\n\n<!-- markdownlint-restore -->\n\n</div>\n\n<p align=\"center\">\n  <a href=\"https://raw.githubusercontent.com/nonebot/adapter-github/master/LICENSE\">\n    <img src=\"https://img.shields.io/github/license/nonebot/adapter-github\" alt=\"license\">\n  </a>\n  <a href=\"https://pypi.python.org/pypi/nonebot-adapter-github\">\n    <img src=\"https://img.shields.io/pypi/v/nonebot-adapter-github\" alt=\"pypi\">\n  </a>\n  <img src=\"https://img.shields.io/badge/python-3.8+-blue\" alt=\"python\">\n  <a href=\"https://results.pre-commit.ci/latest/github/nonebot/adapter-github/master\">\n    <img src=\"https://results.pre-commit.ci/badge/github/nonebot/adapter-github/master.svg\" />\n  </a>\n  <br />\n  <a href=\"https://jq.qq.com/?_wv=1027&k=5OFifDh\">\n    <img src=\"https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=flat-square\" alt=\"QQ Chat Group\">\n  </a>\n  <a href=\"https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&appChannel=share&inviteCode=7b4a3&appChannel=share&businessType=9&from=246610&biz=ka\">\n    <img src=\"https://img.shields.io/badge/QQ%E9%A2%91%E9%81%93-NoneBot-5492ff?style=flat-square\" alt=\"QQ Channel\">\n  </a>\n  <a href=\"https://t.me/botuniverse\">\n    <img src=\"https://img.shields.io/badge/telegram-botuniverse-blue?style=flat-square\" alt=\"Telegram Channel\">\n  </a>\n  <a href=\"https://discord.gg/VKtE6Gdc4h\">\n    <img src=\"https://discordapp.com/api/guilds/847819937858584596/widget.png?style=shield\" alt=\"Discord Server\">\n  </a>\n</p>\n\n## \u5b89\u88c5\n\n```bash\npoetry add nonebot-adapter-github\n# \u6216\u8005\npip install nonebot-adapter-github\n```\n\n## \u52a0\u8f7d\u9002\u914d\u5668\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## \u914d\u7f6e\n\n### \u914d\u7f6e APP\n\n```dotenv\nGITHUB_APPS='\n[\n  {\n    \"app_id\": \"123456\",  # GitHub App ID \u5fc5\u586b\n    \"private_key\": [\n      \"-----BEGIN RSA PRIVATE KEY-----\",\n      \"...\",  # \u5c06\u79c1\u94a5\u6309\u884c\u8f93\u5165\n      \"...\",\n      \"...\",\n      \"-----END RSA PRIVATE KEY-----\"\n    ],  # GitHub App \u79c1\u94a5\u5fc5\u586b\n    \"client_id\": \"123456\",  # OAuth App Client ID \u5fc5\u586b\uff0cGitHub App \u53ef\u9009\n    \"client_secret\": \"xxxxxx\",  # OAuth App Client Secret \u5fc5\u586b\uff0cGitHub App \u53ef\u9009\n    \"webhook_secret\": \"xxxxxx\"  # \u53ef\u9009\n  }\n]'\n```\n\n### \u5176\u4ed6\u914d\u7f6e\n\n```dotenv\nGITHUB_BASE_URL=https://api.github.com\nGITHUB_ACCEPT_FORMAT=full+json\nGITHUB_PREVIEWS=[\"starfox\"]\n```\n\n## \u4f7f\u7528\n\n### WebHook\n\nURL: `/github/webhooks/<app_id>` (GitHub APP) / `/github/webhooks/<client_id>` (OAuth APP)\n\n\u4e8b\u4ef6\u683c\u5f0f:\n\n```python\nclass Event(BaseModel):\n    id: str  # \u4e8b\u4ef6 ID\n    name: str  # \u4e8b\u4ef6\u540d\u79f0\n    payload: Dict[str, Any]  # \u4e8b\u4ef6\u5185\u5bb9\n\n    to_me: bool = False  # \u662f\u5426 @ \u4e86\u673a\u5668\u4eba\u6216\u673a\u5668\u4eba\u6635\u79f0\n```\n\n\u5177\u4f53\u4e8b\u4ef6\u7c7b\u578b\u53ca\u5185\u5bb9\u8bf7\u53c2\u8003 [GitHub Developer](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)\n\n### \u8c03\u7528 API\n\n\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 bot \u8c03\u7528 API\uff0c\u4f46\u662f\u8bf7\u6ce8\u610f **\u53ea\u80fd\u4f7f\u7528\u5f02\u6b65\u63a5\u53e3\uff0c\u53c2\u6570\u5fc5\u987b\u662f keyword args**\u3002\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u53c2\u8003 [githubkit](https://github.com/yanyongyu/githubkit)\u3002\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\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 `githubkit`\uff0c\u4f46\u662f\u5c06\u7ed5\u8fc7 NoneBot \u7684 `call api hook`\u3002\n\n```python\ngithub = bot.github\n```\n\n## \u5f00\u53d1\n\n\u751f\u6210\u4e8b\u4ef6\u5217\u8868\uff1a\n\n```bash\npython -m codegen && ruff check --fix -e . && isort . && black .\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "GitHub adapter for nonebot2",
    "version": "0.4.1",
    "project_urls": {
        "Documentation": "https://github.com/nonebot/adapter-github",
        "Homepage": "https://github.com/nonebot/adapter-github",
        "Repository": "https://github.com/nonebot/adapter-github"
    },
    "split_keywords": [
        "bot",
        "github",
        "webhook"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2de4c484e3aa0df2602b1b458242d9e8349753004832b61fdb50e9aa5b5cdc6",
                "md5": "1ec8ec68f8af3a4c0d628fd810cd1e9d",
                "sha256": "c740149bee51f01c318fd117ec52ebc55a7edf3cdaffb78b985ee9860a76ea89"
            },
            "downloads": -1,
            "filename": "nonebot_adapter_github-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1ec8ec68f8af3a4c0d628fd810cd1e9d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 107931,
            "upload_time": "2024-02-17T15:37:36",
            "upload_time_iso_8601": "2024-02-17T15:37:36.085652Z",
            "url": "https://files.pythonhosted.org/packages/f2/de/4c484e3aa0df2602b1b458242d9e8349753004832b61fdb50e9aa5b5cdc6/nonebot_adapter_github-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8de5d6983ff7fe2b9700b012261a52bfbc62670c19768a7d52f2350da4b2225f",
                "md5": "bcd2ce6dd1e920279aa92894f09c804e",
                "sha256": "c515413457cb2b7477e7e4ed8622aa208ce0d9b65054fd57673d37e91940789f"
            },
            "downloads": -1,
            "filename": "nonebot_adapter_github-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bcd2ce6dd1e920279aa92894f09c804e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 32502,
            "upload_time": "2024-02-17T15:37:38",
            "upload_time_iso_8601": "2024-02-17T15:37:38.040309Z",
            "url": "https://files.pythonhosted.org/packages/8d/e5/d6983ff7fe2b9700b012261a52bfbc62670c19768a7d52f2350da4b2225f/nonebot_adapter_github-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-17 15:37:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nonebot",
    "github_project": "adapter-github",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nonebot-adapter-github"
}
        
Elapsed time: 0.21976s