@@ -76,12 +76,14 @@ jobs:
7676 SHA=$(gh api /repos/$OWNER/$REPO/git/refs/heads/$DEFAULT_BRANCH \
7777 --jq '.object.sha')
7878
79+ # 创建分支
7980 gh api -X POST /repos/$OWNER/$REPO/git/refs \
8081 -f ref="refs/heads/$BRANCH" \
8182 -f sha="$SHA" 2>/dev/null && \
8283 echo "🌿 Created branch: $BRANCH" || \
8384 echo "🌿 Branch already exists: $BRANCH"
8485
86+ # 提交 fix
8587 gh api -X POST \
8688 /repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER/autofix/commits \
8789 -f target_ref="$BRANCH" || {
@@ -90,27 +92,71 @@ jobs:
9092 }
9193 echo "✅ Committed fix to branch: $BRANCH"
9294
93- ALERT_TITLE=$(gh api \
94- /repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER \
95- --jq '.rule.description' )
95+ # 获取 alert 详情
96+ ALERT_INFO=$(gh api \
97+ /repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER )
9698
99+ ALERT_TITLE=$(echo $ALERT_INFO | jq -r '.rule.description')
100+ ALERT_HELP=$(echo $ALERT_INFO | jq -r '.rule.help // "暂无详细说明"' | head -c 800)
101+ ALERT_TAGS=$(echo $ALERT_INFO | jq -r '.rule.tags // [] | join(", ")')
102+ ALERT_FILE=$(echo $ALERT_INFO | jq -r '.most_recent_instance.location.path // "未知文件"')
103+ ALERT_LINE=$(echo $ALERT_INFO | jq -r '.most_recent_instance.location.start_line // "未知行"')
104+ ALERT_URL=$(echo $ALERT_INFO | jq -r '.html_url')
105+ CWE_TAGS=$(echo $ALERT_INFO | jq -r '[.rule.tags[] | select(startswith("external/cwe/"))] | join(", ")')
106+
107+ # 获取 Autofix AI 修复说明
108+ AUTOFIX_DESC=$(gh api \
109+ /repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER/autofix \
110+ --jq '.description // "暂无 AI 修复说明"')
111+
112+ # 创建 Draft PR
97113 gh pr create \
98114 --repo "$OWNER/$REPO" \
99115 --base "$DEFAULT_BRANCH" \
100116 --head "$BRANCH" \
101117 --draft \
102118 --title "[Autofix][$SEC_LEVEL] Alert #$NUMBER: $ALERT_TITLE" \
103- --body "## 🤖 Copilot Autofix 自动修复
119+ --body "## 🤖 Copilot Autofix 自动修复报告
120+
121+ ---
122+
123+ ### 📋 基本信息
124+
125+ | 字段 | 内容 |
126+ |------|------|
127+ | **Alert ID** | [#$NUMBER]($ALERT_URL) |
128+ | **安全级别** | $SEC_LEVEL |
129+ | **规则名称** | $ALERT_TITLE |
130+ | **问题文件** | \`$ALERT_FILE\` 第 $ALERT_LINE 行 |
131+ | **CWE 分类** | $CWE_TAGS |
132+ | **规则标签** | $ALERT_TAGS |
133+
134+ ---
135+
136+ ### 🔍 问题说明
137+
138+ $ALERT_HELP
139+
140+ ---
141+
142+ ### 🤖 AI 修复思路
143+
144+ $AUTOFIX_DESC
145+
146+ ---
147+
148+ ### ✅ Review 检查清单
104149
105- **Alert ID:** #$NUMBER
106- **Security Severity:** $SEC_LEVEL
107- **Rule:** $ALERT_TITLE
150+ - [ ] 理解了漏洞的成因和影响范围
151+ - [ ] 确认 AI 修复逻辑正确,没有遗漏边界情况
152+ - [ ] 确认修复没有改变原有业务逻辑
153+ - [ ] 确认没有引入新的安全问题
154+ - [ ] CI / 单元测试全部通过
155+ - [ ] 如有必要,已补充对应的测试用例
108156
109- 此 PR 由 Copilot Autofix 自动生成,请审核后再 merge。
157+ ---
110158
111- - [ ] 确认修复逻辑正确
112- - [ ] 确认没有引入新问题
113- - [ ] CI 测试通过" && \
159+ > 此 PR 由 GitHub Copilot Autofix 自动生成,请仔细审核后再 merge。" && \
114160 echo "🎉 PR created for alert #$NUMBER" || \
115161 echo "⚠️ PR already exists for alert #$NUMBER"
116162
0 commit comments