style: auto-format with black + isort + prettier [ci skip]
This commit is contained in:
@@ -16,20 +16,24 @@ def run_diagnosis() -> dict:
|
||||
diag_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ci/ci_failure_diagnosis.py")
|
||||
if not os.path.exists(diag_script):
|
||||
diag_script = "scripts/ci/ci_failure_diagnosis.py"
|
||||
|
||||
result = {"category": "unknown", "category_cn": "未知", "severity": "medium",
|
||||
"summary": "", "error_lines": [], "suggestions": [], "auto_fixable": False}
|
||||
|
||||
|
||||
result = {
|
||||
"category": "unknown",
|
||||
"category_cn": "未知",
|
||||
"severity": "medium",
|
||||
"summary": "",
|
||||
"error_lines": [],
|
||||
"suggestions": [],
|
||||
"auto_fixable": False,
|
||||
}
|
||||
|
||||
try:
|
||||
# 运行诊断脚本
|
||||
env = os.environ.copy()
|
||||
env["DIAGNOSIS_OUTPUT"] = "/tmp/ci_diagnosis_result.json"
|
||||
|
||||
proc = subprocess.run(
|
||||
[sys.executable, diag_script],
|
||||
capture_output=True, text=True, timeout=30, env=env
|
||||
)
|
||||
|
||||
|
||||
proc = subprocess.run([sys.executable, diag_script], capture_output=True, text=True, timeout=30, env=env)
|
||||
|
||||
# 尝试读取结果文件
|
||||
output_file = "/tmp/ci_diagnosis_result.json"
|
||||
if os.path.exists(output_file):
|
||||
@@ -40,7 +44,7 @@ def run_diagnosis() -> dict:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f"诊断脚本执行失败: {e}", file=sys.stderr)
|
||||
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -61,21 +65,21 @@ def main() -> int:
|
||||
|
||||
# 运行诊断
|
||||
diagnosis = run_diagnosis()
|
||||
|
||||
|
||||
# 构建卡片内容
|
||||
severity_color = {"high": "red", "medium": "orange", "low": "blue"}
|
||||
card_status = severity_color.get(diagnosis.get("severity", "medium"), "red")
|
||||
|
||||
|
||||
# 标题
|
||||
title = f"❌ CI失败 - {diagnosis.get('category_cn', '未知')}"
|
||||
|
||||
|
||||
# 诊断部分
|
||||
diag_lines = []
|
||||
diag_lines.append(f"**任务**: {failed_job}")
|
||||
diag_lines.append(f"**分类**: {diagnosis.get('category_cn', '未知')}")
|
||||
if diagnosis.get("summary"):
|
||||
diag_lines.append(f"**问题**: {diagnosis['summary']}")
|
||||
|
||||
|
||||
# 错误行
|
||||
error_lines = diagnosis.get("error_lines", [])
|
||||
if error_lines:
|
||||
@@ -85,7 +89,7 @@ def main() -> int:
|
||||
if len(err) > 100:
|
||||
err = err[:97] + "..."
|
||||
diag_lines.append(f"`{err}`")
|
||||
|
||||
|
||||
# 修复建议
|
||||
suggestions = diagnosis.get("suggestions", [])
|
||||
if suggestions:
|
||||
@@ -93,7 +97,7 @@ def main() -> int:
|
||||
diag_lines.append("**修复建议**:")
|
||||
for i, s in enumerate(suggestions[:3], 1):
|
||||
diag_lines.append(f"{i}. {s}")
|
||||
|
||||
|
||||
if diagnosis.get("auto_fixable"):
|
||||
diag_lines.append("")
|
||||
diag_lines.append("💡 *可自动修复的问题,试试Rerun*")
|
||||
@@ -106,7 +110,7 @@ def main() -> int:
|
||||
]
|
||||
if pr_number:
|
||||
info_lines.append(f"**PR**: #{pr_number}")
|
||||
|
||||
|
||||
elements = [
|
||||
{
|
||||
"tag": "div",
|
||||
|
||||
Reference in New Issue
Block a user