Commit 7a3f7a55 authored by 方海彤's avatar 方海彤 👶🏻

feat: refine risk level detection logic in code review results

Improved the accuracy of risk level assessment from LLM responses by implementing a prioritized detection strategy:
1. Matches leading "" for skipped or passed reviews.
2. Specifically searches for an emoji (, ️, or 🚨) within a "Risk Level" line.
3. Implements a fallback that checks for actual list items within the "High Risk" section to avoid false positives triggered by section headers.
parent a9a80307
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"""主流程编排。""" """主流程编排。"""
import os import os
import re
import time import time
from ai_review.config import ( from ai_review.config import (
...@@ -137,9 +138,21 @@ def main(): ...@@ -137,9 +138,21 @@ def main():
print(review_result) print(review_result)
print("=" * 60) print("=" * 60)
has_high_risk = "🔴" in review_result or "高风险" in review_result # 风险等级判定,按可靠度由高到低:
is_pass = "✅" in review_result and not has_high_risk # 1. skip 路径返回的简短结论以 ✅ 开头
risk_emoji = "✅" if is_pass else ("🚨" if has_high_risk else "⚠️") # 2. LLM 在 "风险等级" 行里明确给出 ✅/⚠️/🚨
# 3. fallback:看 "## 🔴 高风险" 节区里是否含实际条目(- [...] 格式),
# 避免被节区标题本身("🔴"/"高风险"字样)误判为高风险
if re.match(r"^\s*✅", review_result):
risk_emoji = "✅"
else:
m = re.search(r"风险等级[::]\s*(✅|⚠️|🚨)", review_result)
if m:
risk_emoji = m.group(1)
else:
sec = re.search(r"##\s*🔴[^\n]*\n([\s\S]*?)(?=\n##|\Z)", review_result)
has_high_risk = bool(sec and re.search(r"^\s*-\s*\[", sec.group(1), re.MULTILINE))
risk_emoji = "🚨" if has_high_risk else "⚠️"
# 构造 diff 链接 # 构造 diff 链接
project_url = os.environ.get("CI_PROJECT_URL", "") project_url = os.environ.get("CI_PROJECT_URL", "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment