Merge pull request #892 from SuanmoSuanyangTechnology/fix/simple-fix

ci(wechat-notify): add Sourcery summary extraction with Qwen fallback
This commit is contained in:
Ke Sun
2026-04-14 18:36:47 +08:00
committed by GitHub

View File

@@ -35,20 +35,52 @@ jobs:
echo "ok=false" >> $GITHUB_OUTPUT echo "ok=false" >> $GITHUB_OUTPUT
fi fi
# 3获取 commits # 3尝试从 PR body 提取 Sourcery 摘要
- name: Get Commits - name: Extract Sourcery Summary
if: steps.check.outputs.ok == 'true' if: steps.check.outputs.ok == 'true'
id: commits id: sourcery
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
python3 << 'PYEOF'
import os, re
body = os.environ.get("PR_BODY", "") or ""
match = re.search(
r"## Summary by Sourcery\s*\n(.*?)(?=\n## |\Z)",
body,
re.DOTALL
)
if match:
summary = match.group(1).strip()
found = "true"
else:
summary = ""
found = "false"
with open("sourcery_summary.txt", "w", encoding="utf-8") as f:
f.write(summary)
with open(os.environ["GITHUB_OUTPUT"], "a") as gh:
gh.write(f"found={found}\n")
gh.write("summary<<EOF\n")
gh.write(summary + "\n")
gh.write("EOF\n")
PYEOF
# 4⃣ Fallback: 获取 commits + 通义千问总结
- name: Get Commits
if: steps.check.outputs.ok == 'true' && steps.sourcery.outputs.found == 'false'
run: | run: |
curl -s \ curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
${{ github.event.pull_request.commits_url }} \ ${{ github.event.pull_request.commits_url }} \
| jq -r '.[].commit.message' | head -n 20 > commits.txt | jq -r '.[].commit.message' | head -n 20 > commits.txt
# 4⃣ 阿里 AI 总结(通义千问) - name: AI Summary (Qwen Fallback)
- name: AI Summary (Qwen) if: steps.check.outputs.ok == 'true' && steps.sourcery.outputs.found == 'false'
if: steps.check.outputs.ok == 'true' id: qwen
id: ai
env: env:
DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }} DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
run: | run: |
@@ -56,34 +88,30 @@ jobs:
import json, os, urllib.request import json, os, urllib.request
with open("commits.txt", "r") as f: with open("commits.txt", "r") as f:
commits = f.read().strip() commits = f.read().strip()
prompt = "请用中文总结以下代码提交输出3-5条要点面向测试人员。直接输出编号列表不要输出标题或前言\n" + commits prompt = "请用中文总结以下代码提交输出3-5条要点面向测试人员。直接输出编号列表不要输出标题或前言\n" + commits
payload = {"model": "qwen-plus", "input": {"prompt": prompt}} payload = {"model": "qwen-plus", "input": {"prompt": prompt}}
data = json.dumps(payload, ensure_ascii=False).encode("utf-8") data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
req = urllib.request.Request( req = urllib.request.Request(
"https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation", "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation",
data=data, data=data,
headers={ headers={
"Authorization": "Bearer " + os.environ["DASHSCOPE_API_KEY"], "Authorization": "Bearer " + os.environ["DASHSCOPE_API_KEY"],
"Content-Type": "application/json" "Content-Type": "application/json"
} }
) )
resp = urllib.request.urlopen(req) resp = urllib.request.urlopen(req)
result = json.loads(resp.read().decode()) result = json.loads(resp.read().decode())
summary = result.get("output", {}).get("text", "AI 摘要生成失败") summary = result.get("output", {}).get("text", "AI 摘要生成失败")
print(summary)
with open("ai_summary.txt", "w", encoding="utf-8") as f: with open(os.environ["GITHUB_OUTPUT"], "a") as gh:
f.write(summary) gh.write("summary<<EOF\n")
gh.write(summary + "\n")
gh.write("EOF\n")
PYEOF PYEOF
SUMMARY=$(cat ai_summary.txt)
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# 5⃣ 企业微信通知Markdown # 5⃣ 企业微信通知Markdown
- name: Notify WeChat - name: Notify WeChat
if: steps.check.outputs.ok == 'true' if: steps.check.outputs.ok == 'true'
@@ -93,17 +121,27 @@ jobs:
AUTHOR: ${{ github.event.pull_request.user.login }} AUTHOR: ${{ github.event.pull_request.user.login }}
PR_TITLE: ${{ github.event.pull_request.title }} PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }} PR_URL: ${{ github.event.pull_request.html_url }}
AI_SUMMARY: ${{ steps.ai.outputs.summary }} SOURCERY_FOUND: ${{ steps.sourcery.outputs.found }}
SOURCERY_SUMMARY: ${{ steps.sourcery.outputs.summary }}
QWEN_SUMMARY: ${{ steps.qwen.outputs.summary }}
run: | run: |
python3 << 'PYEOF' python3 << 'PYEOF'
import json, os, urllib.request import json, os, urllib.request
if os.environ.get("SOURCERY_FOUND") == "true":
label = "Summary by Sourcery"
summary = os.environ.get("SOURCERY_SUMMARY", "")
else:
label = "AI变更摘要"
summary = os.environ.get("QWEN_SUMMARY", "AI 摘要生成失败")
content = ( content = (
"## 🚀 Release 发布通知\n" "## 🚀 Release 发布通知\n"
"> 📦 **分支**: " + os.environ["BRANCH"] + "\n" "> 📦 **分支**: " + os.environ["BRANCH"] + "\n"
"> 👤 **提交人**: " + os.environ["AUTHOR"] + "\n" "> 👤 **提交人**: " + os.environ["AUTHOR"] + "\n"
"> 📝 **标题**: " + os.environ["PR_TITLE"] + "\n\n" "> 📝 **标题**: " + os.environ["PR_TITLE"] + "\n\n"
"### 🧠 AI变更摘要\n" + "### 🧠 " + label + "\n" +
os.environ["AI_SUMMARY"] + "\n\n" summary + "\n\n"
"---\n" "---\n"
"🔗 [查看PR详情](" + os.environ["PR_URL"] + ")" "🔗 [查看PR详情](" + os.environ["PR_URL"] + ")"
) )