ci(wechat-notify): extract payload building logic to Python script
- Create new `.github/scripts/build_wechat_payload.py` to handle WeChat payload generation - Replace inline Python string concatenation with dedicated script for better maintainability - Add checkout step to access the script during workflow execution - Simplify workflow by delegating payload construction to external script - Improve code readability and reusability for future notification enhancements
This commit is contained in:
24
.github/scripts/build_wechat_payload.py
vendored
Normal file
24
.github/scripts/build_wechat_payload.py
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
branch = os.environ.get("BRANCH", "")
|
||||||
|
author = os.environ.get("AUTHOR", "")
|
||||||
|
pr_title = os.environ.get("PR_TITLE", "")
|
||||||
|
pr_url = os.environ.get("PR_URL", "")
|
||||||
|
ai_summary = os.environ.get("AI_SUMMARY", "")
|
||||||
|
|
||||||
|
content = (
|
||||||
|
"## 🚀 Release 发布通知\n"
|
||||||
|
f"> 📦 **分支**: {branch}\n"
|
||||||
|
f"> 👤 **提交人**: {author}\n"
|
||||||
|
f"> 📝 **标题**: {pr_title}\n\n"
|
||||||
|
"### 🧠 AI变更摘要\n"
|
||||||
|
f"{ai_summary}\n\n"
|
||||||
|
"---\n"
|
||||||
|
f"🔗 [查看PR详情]({pr_url})"
|
||||||
|
)
|
||||||
|
|
||||||
|
payload = {"msgtype": "markdown", "markdown": {"content": content}}
|
||||||
|
|
||||||
|
with open("wechat_payload.json", "w", encoding="utf-8") as f:
|
||||||
|
json.dump(payload, f, ensure_ascii=False)
|
||||||
21
.github/workflows/release-notify-wechat.yml
vendored
21
.github/workflows/release-notify-wechat.yml
vendored
@@ -79,6 +79,10 @@ jobs:
|
|||||||
echo "EOF" >> $GITHUB_OUTPUT
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# 5️⃣ 企业微信通知(Markdown)
|
# 5️⃣ 企业微信通知(Markdown)
|
||||||
|
- name: Checkout for script
|
||||||
|
if: steps.check.outputs.ok == 'true'
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Notify WeChat
|
- name: Notify WeChat
|
||||||
if: steps.check.outputs.ok == 'true'
|
if: steps.check.outputs.ok == 'true'
|
||||||
env:
|
env:
|
||||||
@@ -89,22 +93,7 @@ jobs:
|
|||||||
PR_URL: ${{ github.event.pull_request.html_url }}
|
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||||
AI_SUMMARY: ${{ steps.ai.outputs.summary }}
|
AI_SUMMARY: ${{ steps.ai.outputs.summary }}
|
||||||
run: |
|
run: |
|
||||||
python3 -c "
|
python3 .github/scripts/build_wechat_payload.py
|
||||||
import json, os
|
|
||||||
content = (
|
|
||||||
'## 🚀 Release 发布通知\n'
|
|
||||||
'> 📦 **分支**: ' + os.environ['BRANCH'] + '\n'
|
|
||||||
'> 👤 **提交人**: ' + os.environ['AUTHOR'] + '\n'
|
|
||||||
'> 📝 **标题**: ' + os.environ['PR_TITLE'] + '\n\n'
|
|
||||||
'### 🧠 AI变更摘要\n'
|
|
||||||
+ os.environ['AI_SUMMARY'] + '\n\n'
|
|
||||||
'---\n'
|
|
||||||
'🔗 [查看PR详情](' + os.environ['PR_URL'] + ')'
|
|
||||||
)
|
|
||||||
payload = {'msgtype': 'markdown', 'markdown': {'content': content}}
|
|
||||||
with open('wechat_payload.json', 'w') as f:
|
|
||||||
json.dump(payload, f, ensure_ascii=False)
|
|
||||||
"
|
|
||||||
|
|
||||||
curl -s "$WECHAT_WEBHOOK" \
|
curl -s "$WECHAT_WEBHOOK" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
|
|||||||
Reference in New Issue
Block a user