Skip to content

Commit 1b78050

Browse files
committed
ci:update
1 parent 0663221 commit 1b78050

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

.github/workflows/codeql-to-commit.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
GH_TOKEN: ${{ secrets.AUTOFIX_TOKEN }}
2020
OWNER: ${{ github.repository_owner }}
2121
REPO: ${{ github.event.repository.name }}
22-
run: |
23-
# 获取默认分支名
22+
run: |
2423
DEFAULT_BRANCH=$(gh api /repos/$OWNER/$REPO --jq '.default_branch')
2524
echo "Default branch: $DEFAULT_BRANCH"
2625
27-
for SEVERITY in "critical" "error" "warning"; do
26+
# ← 去掉 "warning",只处理 critical 和 error(High)
27+
for SEVERITY in "critical" "error"; do
2828
echo "====== Processing severity: $SEVERITY ======"
2929
3030
ALERTS=$(gh api \
@@ -68,23 +68,50 @@ jobs:
6868
if [ "$EXISTING" = "success" ]; then
6969
BRANCH="autofix/${SEVERITY}/alert-${NUMBER}"
7070
71-
# 获取默认分支最新的 SHA
7271
SHA=$(gh api /repos/$OWNER/$REPO/git/refs/heads/$DEFAULT_BRANCH \
7372
--jq '.object.sha')
7473
75-
# 先创建分支
74+
# 创建分支
7675
gh api -X POST /repos/$OWNER/$REPO/git/refs \
7776
-f ref="refs/heads/$BRANCH" \
7877
-f sha="$SHA" 2>/dev/null && \
7978
echo "🌿 Created branch: $BRANCH" || \
8079
echo "🌿 Branch already exists: $BRANCH"
8180
82-
# 再提交 fix 到该分支
81+
# 提交 fix
8382
gh api -X POST \
8483
/repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER/autofix/commits \
85-
-f target_ref="$BRANCH" && \
86-
echo "✅ Committed fix to branch: $BRANCH" || \
87-
echo "❌ Failed to commit fix for alert #$NUMBER"
84+
-f target_ref="$BRANCH" || {
85+
echo "❌ Failed to commit fix for alert #$NUMBER"
86+
continue
87+
}
88+
echo "✅ Committed fix to branch: $BRANCH"
89+
90+
# 获取 alert 标题用于 PR 描述
91+
ALERT_TITLE=$(gh api \
92+
/repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER \
93+
--jq '.rule.description')
94+
95+
# 自动创建 PR(Draft 状态,需要你审核后才能 merge)
96+
gh pr create \
97+
--repo "$OWNER/$REPO" \
98+
--base "$DEFAULT_BRANCH" \
99+
--head "$BRANCH" \
100+
--draft \
101+
--title "[Autofix][$SEVERITY] Alert #$NUMBER: $ALERT_TITLE" \
102+
--body "## 🤖 Copilot Autofix 自动修复
103+
104+
**Alert ID:** #$NUMBER
105+
**Severity:** $SEVERITY
106+
**Rule:** $ALERT_TITLE
107+
108+
此 PR 由 Copilot Autofix 自动生成,请审核后再 merge。
109+
110+
- [ ] 确认修复逻辑正确
111+
- [ ] 确认没有引入新问题
112+
- [ ] CI 测试通过" && \
113+
echo "🎉 PR created for alert #$NUMBER" || \
114+
echo "⚠️ PR already exists for alert #$NUMBER"
88115
89116
else
90117
echo "⚠️ Autofix not available for alert #$NUMBER (status: $EXISTING), skipping"

0 commit comments

Comments
 (0)