Files
water-management-system/scripts/notify.py
T

29 lines
1006 B
Python
Raw Normal View History

#!/usr/bin/env python3
"""CI 结果企业微信机器人通知(Issue #90)。"""
import argparse, json, os, sys, urllib.request
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--status", required=True)
ap.add_argument("--commit", default="")
args = ap.parse_args()
webhook = os.environ.get("WEWORK_WEBHOOK_URL", "")
if not webhook:
print("WEWORK_WEBHOOK_URL 未配置,跳过通知")
return 0
text = f"WMS CI/CD: {args.status} (commit {args.commit[:8]})"
req = urllib.request.Request(
webhook,
data=json.dumps({"msgtype": "text", "text": {"content": text}}).encode(),
headers={"Content-Type": "application/json"},
)
try:
with urllib.request.urlopen(req, timeout=10) as resp:
print("notify sent:", resp.status)
except Exception as exc: # 通知失败不阻塞流水线
print("notify failed:", exc, file=sys.stderr)
return 0
if __name__ == "__main__":
sys.exit(main())