Skip to content

feat: 支持 Push 和 Release 事件通知及 Webhook 解析修复#6

Merged
Soulter merged 2 commits into
Soulter:masterfrom
crt106:master
Jun 13, 2026
Merged

feat: 支持 Push 和 Release 事件通知及 Webhook 解析修复#6
Soulter merged 2 commits into
Soulter:masterfrom
crt106:master

Conversation

@crt106

@crt106 crt106 commented Mar 7, 2026

Copy link
Copy Markdown

📝 改进描述

在插件原有的基础上,增加了处理 GitHub Push (Commits)Release 事件的功能。
同时修复了 Webhook 模式下当接收到 application/x-www-form-urlencoded 数据时解析失败的问题。

✨ 新增功能

  1. Push 事件提醒:支持从 Webhook 和轮询(Polling)触发,并展示主要提交摘要及差异对比链接。
  2. Release 事件提醒:在项目发版(发布/预发布等状态变化)时向订阅者发送带版本号及详细说明的卡片。
  3. 轮询机制改进:原有的 _fetch_new_items 方法现在会一并获取 Issue/PR、Commits 和 Releases。

🐛 修复问题

  • 修复当 Content-Typeapplication/x-www-form-urlencoded 时,因为缺失字段导致的 JSON 格式解析出 NoneType object has no attribute get 的错误。现在会自动通过 request.form 获取表单中 payload 参数进行解析。

📌 测试情况

  • 已在本地测试通过 application/jsonapplication/x-www-form-urlencoded 两种 Webhook 推送。
  • 轮询逻辑时间戳已对齐 UTC 保证时区兼容性。

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 在现有 GitHub Cards 插件基础上,新增对 PushRelease 事件的通知支持,并增强 Webhook 在 application/x-www-form-urlencoded 场景下的 payload 解析兼容性,同时扩展轮询逻辑以抓取 commits/releases。

Changes:

  • Webhook:兼容 application/x-www-form-urlencoded(从 request.form["payload"] 提取 JSON)。
  • 轮询:_fetch_new_items 扩展为同时抓取 Issue/PR、Commits、Releases,并在通知侧识别新类型。
  • 格式化:新增 Push/Release Webhook 消息格式化函数;插件元数据版本号更新。

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
webhook_server.py 增强 Webhook 请求体解析,兼容表单编码 payload。
main.py 扩展轮询抓取 commits/releases、通知逻辑支持新类型,并新增 push/release Webhook 分发。
formatters.py 新增 push/release 的 Webhook 文本消息格式化。
metadata.yaml 插件版本号升级到 1.1.1。
Comments suppressed due to low confidence (1)

main.py:535

  • new_items 按 “Issue/PR → Commits → Releases” 分段 append,最终通知顺序不是按时间排序;当一次轮询同时发现多种类型更新时,用户会看到乱序通知。建议在返回/通知前按各类型的时间戳统一排序(例如 created_at / commit.committer.date / published_at)。
            if new_items:
                logger.info(f"找到 {len(new_items)} 个新的 items 在 {repo}")
            else:
                logger.debug(f"没有找到新的 items 在 {repo}")


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread metadata.yaml
desc: GitHub 相关链接自动发送 GitHub 仓库简介/issue/pr卡片、订阅 GitHub 仓库事件 # 插件描述
help:
version: 1.1.0 # 插件版本
version: 1.1.1 # 插件版本
Comment thread main.py
Comment thread main.py

# 3. Fetch Releases
try:
params_releases = {"per_page": 5}
Comment thread main.py
Comment on lines +576 to +586
elif item["_astrbot_type"] == "release":
tag_name = item.get("tag_name", "未知版本")
name = item.get("name") or tag_name
author = item.get("author", {}).get("login", "未知")
url = item.get("html_url", "")
message = (
f"[GitHub 更新] 仓库 {repo} 发布了新版本:\n"
f"版本: {name} ({tag_name})\n"
f"发布者: {author}\n"
f"链接: {url}"
)
Comment thread main.py
Comment on lines +439 to 445
params_issues = {
"sort": "created",
"direction": "desc",
"state": "all",
"per_page": 10,
"since": last_check_dt.isoformat() + "Z",
}
Comment thread formatters.py
Comment on lines +540 to +555
actor = (sender or {}).get("login") or "未知"

message_lines = [
f"[GitHub Webhook] 仓库 {repo} 代码推送",
f"分支: {branch_or_tag}",
f"触发人: {actor}",
f"新增 {len(commits)} 个提交:"
]

for commit in commits[:3]:
msg = commit.get("message", "").split("\n")[0]
sha = commit.get("id", "")[:7]
message_lines.append(f"- {sha} {msg}")

if len(commits) > 3:
message_lines.append(f"... 等共 {len(commits)} 个提交")
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Soulter Soulter merged commit a765301 into Soulter:master Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants