feat(toolchain): CI failure mail includes direct CI run URL
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:
@@ -459,11 +459,33 @@ async def _handle_issue_comment(payload: Dict[str, Any]) -> None:
|
|||||||
# 提取错误摘要(取 comment body 前 500 字符)
|
# 提取错误摘要(取 comment body 前 500 字符)
|
||||||
error_summary = body[:500] if body else "(无错误信息)"
|
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", {
|
text = render_template("ci_failure", {
|
||||||
"repo": repo,
|
"repo": repo,
|
||||||
"pr_number": str(issue_number),
|
"pr_number": str(issue_number),
|
||||||
"branch": branch,
|
"branch": branch,
|
||||||
"error_summary": error_summary,
|
"error_summary": error_summary,
|
||||||
|
"ci_url": ci_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
title = f"CI 失败: {repo}#{issue_number}"
|
title = f"CI 失败: {repo}#{issue_number}"
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ PR: http://192.168.2.154:3000/{repo}/pulls/{pr_number}
|
|||||||
{error_summary}
|
{error_summary}
|
||||||
|
|
||||||
请检查 CI 日志并修复。修复后 push 会自动触发 CI。
|
请检查 CI 日志并修复。修复后 push 会自动触发 CI。
|
||||||
|
|
||||||
|
CI 日志链接: {ci_url}
|
||||||
|
|||||||
Reference in New Issue
Block a user