nonebot-plugin-github-release 0.1.0__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.
Files changed (33) hide show
  1. nonebot_plugin_github_release-0.1.0/.env.example +33 -0
  2. nonebot_plugin_github_release-0.1.0/.gitattributes +6 -0
  3. nonebot_plugin_github_release-0.1.0/.github/workflows/release.yml +35 -0
  4. nonebot_plugin_github_release-0.1.0/.gitignore +25 -0
  5. nonebot_plugin_github_release-0.1.0/LICENSE +21 -0
  6. nonebot_plugin_github_release-0.1.0/PKG-INFO +109 -0
  7. nonebot_plugin_github_release-0.1.0/README.md +62 -0
  8. nonebot_plugin_github_release-0.1.0/docs/card-example.png +0 -0
  9. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/__init__.py +69 -0
  10. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/card.py +352 -0
  11. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/commands.py +258 -0
  12. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/config.py +70 -0
  13. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/latest.py +60 -0
  14. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/models.py +64 -0
  15. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/plan.py +47 -0
  16. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/render.py +174 -0
  17. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/source.py +170 -0
  18. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/store.py +147 -0
  19. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/versions.py +52 -0
  20. nonebot_plugin_github_release-0.1.0/nonebot_plugin_github_release/watch.py +198 -0
  21. nonebot_plugin_github_release-0.1.0/pyproject.toml +66 -0
  22. nonebot_plugin_github_release-0.1.0/tests/conftest.py +20 -0
  23. nonebot_plugin_github_release-0.1.0/tests/fixtures/sample_release_body.md +28 -0
  24. nonebot_plugin_github_release-0.1.0/tests/test_card.py +91 -0
  25. nonebot_plugin_github_release-0.1.0/tests/test_latest.py +45 -0
  26. nonebot_plugin_github_release-0.1.0/tests/test_plan.py +71 -0
  27. nonebot_plugin_github_release-0.1.0/tests/test_render.py +76 -0
  28. nonebot_plugin_github_release-0.1.0/tests/test_source.py +75 -0
  29. nonebot_plugin_github_release-0.1.0/tests/test_store.py +66 -0
  30. nonebot_plugin_github_release-0.1.0/tests/test_versions.py +38 -0
  31. nonebot_plugin_github_release-0.1.0/tools/cardpreview.py +105 -0
  32. nonebot_plugin_github_release-0.1.0/tools/loadcheck.py +96 -0
  33. nonebot_plugin_github_release-0.1.0/tools/preview.py +95 -0
@@ -0,0 +1,33 @@
1
+ # ============ GitHub 发布推送 ============
2
+
3
+ # 监控哪些仓库(owner/repo 格式)。留空也可以,直接在群里用 /gh订阅 加更灵活
4
+ GH_WATCH_REPOS=[]
5
+
6
+ # 默认接收推送的群:与上面的仓库做组合,等价于「这些群都订阅这些仓库」
7
+ GH_WATCH_GROUPS=[]
8
+
9
+ # 轮询间隔(分钟),默认 10
10
+ GH_WATCH_INTERVAL_MINUTES=10
11
+
12
+ # 是否连 alpha / beta / rc 一起推,默认 True
13
+ GH_WATCH_INCLUDE_PRERELEASE=True
14
+
15
+ # 没有正文的 release 不算公告,默认 True
16
+ GH_WATCH_REQUIRE_BODY=True
17
+
18
+ # 可选:GitHub Token(匿名限额 60 次/小时且按出口 IP 共享,多仓库建议配上)
19
+ GH_WATCH_GITHUB_TOKEN=
20
+
21
+ # 可选:代理,服务器直连 GitHub 不稳时使用
22
+ GH_WATCH_PROXY=
23
+
24
+ # 文本推送 / 查询时的正文上限
25
+ GH_WATCH_MAX_CHARS=600
26
+ GH_WATCH_QUERY_MAX_CHARS=1200
27
+
28
+ # 是否发送卡片图片(需要 nonebot-plugin-htmlrender + chromium)
29
+ GH_WATCH_SEND_IMAGE=True
30
+ GH_WATCH_CARD_WIDTH=900
31
+ GH_WATCH_CARD_MAX_HEIGHT=1500
32
+ GH_WATCH_CARD_MAX_CHARS=2400
33
+ GH_WATCH_CARD_SHOW_REACTIONS=True
@@ -0,0 +1,6 @@
1
+ # 服务器是 Linux,统一用 LF,避免 CRLF 混进部署目录
2
+ * text=auto eol=lf
3
+
4
+ *.png binary
5
+ *.jpg binary
6
+ *.ico binary
@@ -0,0 +1,35 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - run: python -m pip install build
16
+ - run: python -m build
17
+ - uses: actions/upload-artifact@v4
18
+ with:
19
+ name: dist
20
+ path: dist/
21
+
22
+ publish:
23
+ needs: build
24
+ runs-on: ubuntu-latest
25
+ # 必须和 PyPI 待发布者里填的 Environment name 一致
26
+ environment: pypi
27
+ permissions:
28
+ # Trusted Publishing 靠这个,不需要任何密钥
29
+ id-token: write
30
+ steps:
31
+ - uses: actions/download-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,25 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+
10
+ # 测试与缓存
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+
15
+ # 本地配置与运行数据
16
+ .env
17
+ .env.*
18
+ !.env.example
19
+ data/
20
+
21
+ # 编辑器 / 系统
22
+ .idea/
23
+ .vscode/
24
+ .DS_Store
25
+ Thumbs.db
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ns
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.5
2
+ Name: nonebot-plugin-github-release
3
+ Version: 0.1.0
4
+ Summary: 监控任意 GitHub 仓库的 release,把新版本推送到 QQ 群
5
+ Project-URL: Homepage, https://github.com/NSQX13579/nonebot-plugin-github-release
6
+ Project-URL: Repository, https://github.com/NSQX13579/nonebot-plugin-github-release
7
+ Author-email: ns <102937666+NSQX13579@users.noreply.github.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 ns
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: github,nonebot,nonebot2,release,watch
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Programming Language :: Python :: 3
34
+ Requires-Python: >=3.9
35
+ Requires-Dist: httpx>=0.26
36
+ Requires-Dist: nonebot-adapter-onebot>=2.4.0
37
+ Requires-Dist: nonebot-plugin-apscheduler>=0.5.0
38
+ Requires-Dist: nonebot-plugin-localstore>=0.7.0
39
+ Requires-Dist: nonebot2>=2.4.0
40
+ Requires-Dist: pydantic>=2.0
41
+ Requires-Dist: tzdata; sys_platform == 'win32'
42
+ Provides-Extra: image
43
+ Requires-Dist: nonebot-plugin-htmlrender>=0.6.7; extra == 'image'
44
+ Provides-Extra: test
45
+ Requires-Dist: pytest>=7.0; extra == 'test'
46
+ Description-Content-Type: text/markdown
47
+
48
+ # nonebot-plugin-github-release
49
+
50
+ 监控任意 GitHub 仓库的 release,把新版本推送到 QQ 群。按群订阅,每个群只收自己关心的仓库。
51
+
52
+ 本插件由 [nonebot-plugin-dsh-release](https://github.com/NSQX13579/nonebot-plugin-dsh-release) 改进而得。
53
+
54
+ ## 安装
55
+
56
+ ```bash
57
+ pip install nonebot-plugin-github-release
58
+ playwright install chromium # 卡片图片需要,不装会自动回退纯文本
59
+ ```
60
+
61
+ 依赖 `nonebot-plugin-apscheduler`(定时)和 `nonebot-plugin-localstore`(数据目录),装包时会一并带上。
62
+
63
+ ## 配置
64
+
65
+ `.env`(完整模板见 `.env.example`):
66
+
67
+ ```dotenv
68
+ # 监控哪些仓库(留空也行,直接在群里 /gh订阅 更灵活)
69
+ GH_WATCH_REPOS=[]
70
+ GH_WATCH_GROUPS=[]
71
+
72
+ # 可选:匿名 API 限额 60 次/小时且按出口 IP 共享,多仓库建议配上
73
+ GH_WATCH_GITHUB_TOKEN=
74
+ ```
75
+
76
+ 插件不带任何默认仓库——用群里的 `/gh订阅 owner/repo` 加,或者把上面的列表填上。
77
+
78
+ ## 指令
79
+
80
+ | 指令 | 权限 | 说明 |
81
+ | --- | --- | --- |
82
+ | `/gh订阅 owner/repo` | 群管 | 本群订阅某个仓库 |
83
+ | `/gh退订 owner/repo` | 群管 | 取消订阅 |
84
+ | `/gh列表` | 所有人 | 看本群订阅了哪些仓库 |
85
+ | `/gh公告 owner/repo` | 所有人 | 最新一条 release 全文 |
86
+ | `/gh公告 owner/repo 5` | 所有人 | 列最近 5 条(最多 10) |
87
+ | `/gh公告 owner/repo v1.2` | 所有人 | 按版本号检索 |
88
+ | `/gh状态` | 所有人 | 推送状态 |
89
+ | `/gh检查` | 超管 | 立刻检查一次,不等下一轮 |
90
+
91
+ ## 消息长什么样
92
+
93
+ ![示例](docs/card-example.png)
94
+
95
+ 图下面另附一行带链接的文字——图片里的地址点不了。卡片上的头像、发布时间、版本号、正文、表情计数都是 GitHub 的真实数据。
96
+
97
+ **渲染出任何问题都会回退纯文本**(没装 htmlrender、没装 chromium、超时都算),只打一条警告日志,推送不受影响。
98
+
99
+ ## 行为说明
100
+
101
+ - 数据源:Releases API 为主,被限流时自动切到不限流的 `releases.atom`
102
+ - 首次运行只建推送基线,不会把历史 release 刷进群
103
+ - 以 tag 去重,失败的不写进已推送列表,下一轮自然重试
104
+ - 中英双语正文默认只保留中文段,`GH_WATCH_BODY_LANGUAGE=all` 可改成两段都留
105
+ - `GH_WATCH_INCLUDE_PRERELEASE=False` 则只推正式版
106
+
107
+ ## License
108
+
109
+ MIT
@@ -0,0 +1,62 @@
1
+ # nonebot-plugin-github-release
2
+
3
+ 监控任意 GitHub 仓库的 release,把新版本推送到 QQ 群。按群订阅,每个群只收自己关心的仓库。
4
+
5
+ 本插件由 [nonebot-plugin-dsh-release](https://github.com/NSQX13579/nonebot-plugin-dsh-release) 改进而得。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install nonebot-plugin-github-release
11
+ playwright install chromium # 卡片图片需要,不装会自动回退纯文本
12
+ ```
13
+
14
+ 依赖 `nonebot-plugin-apscheduler`(定时)和 `nonebot-plugin-localstore`(数据目录),装包时会一并带上。
15
+
16
+ ## 配置
17
+
18
+ `.env`(完整模板见 `.env.example`):
19
+
20
+ ```dotenv
21
+ # 监控哪些仓库(留空也行,直接在群里 /gh订阅 更灵活)
22
+ GH_WATCH_REPOS=[]
23
+ GH_WATCH_GROUPS=[]
24
+
25
+ # 可选:匿名 API 限额 60 次/小时且按出口 IP 共享,多仓库建议配上
26
+ GH_WATCH_GITHUB_TOKEN=
27
+ ```
28
+
29
+ 插件不带任何默认仓库——用群里的 `/gh订阅 owner/repo` 加,或者把上面的列表填上。
30
+
31
+ ## 指令
32
+
33
+ | 指令 | 权限 | 说明 |
34
+ | --- | --- | --- |
35
+ | `/gh订阅 owner/repo` | 群管 | 本群订阅某个仓库 |
36
+ | `/gh退订 owner/repo` | 群管 | 取消订阅 |
37
+ | `/gh列表` | 所有人 | 看本群订阅了哪些仓库 |
38
+ | `/gh公告 owner/repo` | 所有人 | 最新一条 release 全文 |
39
+ | `/gh公告 owner/repo 5` | 所有人 | 列最近 5 条(最多 10) |
40
+ | `/gh公告 owner/repo v1.2` | 所有人 | 按版本号检索 |
41
+ | `/gh状态` | 所有人 | 推送状态 |
42
+ | `/gh检查` | 超管 | 立刻检查一次,不等下一轮 |
43
+
44
+ ## 消息长什么样
45
+
46
+ ![示例](docs/card-example.png)
47
+
48
+ 图下面另附一行带链接的文字——图片里的地址点不了。卡片上的头像、发布时间、版本号、正文、表情计数都是 GitHub 的真实数据。
49
+
50
+ **渲染出任何问题都会回退纯文本**(没装 htmlrender、没装 chromium、超时都算),只打一条警告日志,推送不受影响。
51
+
52
+ ## 行为说明
53
+
54
+ - 数据源:Releases API 为主,被限流时自动切到不限流的 `releases.atom`
55
+ - 首次运行只建推送基线,不会把历史 release 刷进群
56
+ - 以 tag 去重,失败的不写进已推送列表,下一轮自然重试
57
+ - 中英双语正文默认只保留中文段,`GH_WATCH_BODY_LANGUAGE=all` 可改成两段都留
58
+ - `GH_WATCH_INCLUDE_PRERELEASE=False` 则只推正式版
59
+
60
+ ## License
61
+
62
+ MIT
@@ -0,0 +1,69 @@
1
+ """nonebot-plugin-github-release
2
+
3
+ 监控任意 GitHub 仓库的 release,把新版本推送到 QQ 群。
4
+
5
+ - 数据源:Releases API 为主,被限流时自动切到不限流的 `releases.atom`
6
+ - 推送形式:默认发一张类 GitHub 卡片的图片,渲染失败自动回退纯文本
7
+ - 按群订阅:`/gh订阅 owner/repo`,每个群只收自己关心的仓库
8
+ """
9
+
10
+ from datetime import datetime, timedelta
11
+
12
+ from nonebot import require
13
+
14
+ require("nonebot_plugin_apscheduler")
15
+
16
+ from nonebot.log import logger # noqa: E402
17
+ from nonebot.plugin import PluginMetadata # noqa: E402
18
+ from nonebot_plugin_apscheduler import scheduler # noqa: E402
19
+
20
+ from . import commands as _commands # noqa: E402,F401
21
+ from .config import Config, load_config # noqa: E402
22
+ from .watch import check_once # noqa: E402
23
+
24
+ __all__ = ["Config", "check_once"]
25
+
26
+ __plugin_meta__ = PluginMetadata(
27
+ name="GitHub 发布推送",
28
+ description="监控 GitHub 仓库的 release,把新版本推送到 QQ 群",
29
+ usage=(
30
+ "/gh订阅 owner/repo 让本群订阅(群管)\n"
31
+ "/gh公告 owner/repo 看最新 release\n"
32
+ "/gh状态 看推送状态"
33
+ ),
34
+ type="application",
35
+ homepage="https://github.com/NSQX13579/nonebot-plugin-github-release",
36
+ config=Config,
37
+ supported_adapters={"~onebot.v11"},
38
+ )
39
+
40
+ _JOB_ID = "github_release_watch"
41
+
42
+ plugin_config: Config = load_config()
43
+
44
+
45
+ async def _scheduled_check() -> None:
46
+ result = await check_once(plugin_config)
47
+ logger.debug(f"[gh-release] 定时检查:{result.status} | {result.detail}")
48
+
49
+
50
+ scheduler.add_job(
51
+ _scheduled_check,
52
+ "interval",
53
+ minutes=max(1, plugin_config.gh_watch_interval_minutes),
54
+ # 启动 30 秒后先跑一轮,不用干等一个完整间隔
55
+ next_run_time=datetime.now() + timedelta(seconds=30),
56
+ id=_JOB_ID,
57
+ replace_existing=True,
58
+ coalesce=True,
59
+ max_instances=1,
60
+ misfire_grace_time=300,
61
+ )
62
+
63
+ if plugin_config.gh_watch_repos or plugin_config.gh_watch_groups:
64
+ logger.info(
65
+ f"[gh-release] 已启动:每 {plugin_config.gh_watch_interval_minutes} 分钟检查 "
66
+ f"{len(plugin_config.gh_watch_repos)} 个仓库"
67
+ )
68
+ else:
69
+ logger.info("[gh-release] 尚未配置仓库,可在群里用 /gh订阅 owner/repo 添加")