feat(toolchain): CI failure mail includes direct CI run URL
CI / lint (pull_request) Failing after 6s
CI / test (pull_request) Has been skipped
CI / notify-on-failure (pull_request) Successful in 1s

Extract commit sha from CI comment body, query Gitea commit status
API to get the failed job's target_url, and include it in the Mail.
This commit is contained in:
cfdaily
2026-06-10 08:14:32 +08:00
parent a72e08403f
commit c4f615ce7f
2 changed files with 24 additions and 0 deletions
+22
View File
@@ -459,11 +459,33 @@ async def _handle_issue_comment(payload: Dict[str, Any]) -> None:
# 提取错误摘要(取 comment body 前 500 字符)
error_summary = body[:500] if body else "(无错误信息)"
# 尝试从 commit sha 查询 CI run URL
ci_url = ""
sha_match = re.search(r"commit:\s*`?([0-9a-f]{40})`?", body)
if sha_match:
try:
resp = requests.get(
f"{_GITEA_BASE}/commits/{sha_match.group(1)}/status",
headers={"Authorization": f"token {_GITEA_TOKEN}"},
timeout=5,
)
if resp.ok:
statuses = resp.json().get("statuses", [])
for s in statuses:
if s.get("status") == "failure" or s.get("state") == "failure":
target = s.get("target_url", "")
if target:
ci_url = "http://192.168.2.154:3000" + target if target.startswith("/") else target
break
except Exception as exc:
logger.warning("Failed to query CI run URL: %s", exc)
text = render_template("ci_failure", {
"repo": repo,
"pr_number": str(issue_number),
"branch": branch,
"error_summary": error_summary,
"ci_url": ci_url,
})
title = f"CI 失败: {repo}#{issue_number}"
+2
View File
@@ -7,3 +7,5 @@ PR: http://192.168.2.154:3000/{repo}/pulls/{pr_number}
{error_summary}
请检查 CI 日志并修复。修复后 push 会自动触发 CI。
CI 日志链接: {ci_url}