Skip to content

Commit ab5e58d

Browse files
committed
ci:update
1 parent e5fc1b3 commit ab5e58d

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Auto Copilot Autofix (High & Medium Only)
22

33
on:
4+
workflow_dispatch:
45
workflow_run:
56
workflows: ["CodeQL Advanced"]
67
types: [completed]
@@ -23,23 +24,24 @@ jobs:
2324
DEFAULT_BRANCH=$(gh api /repos/$OWNER/$REPO --jq '.default_branch')
2425
echo "Default branch: $DEFAULT_BRANCH"
2526
26-
# ← 去掉 "warning",只处理 critical 和 error(High
27-
for SEVERITY in "critical" "error"; do
28-
echo "====== Processing severity: $SEVERITY ======"
27+
# 用 security_severity_level 过滤,对应界面上的 Critical/High/Medium
28+
for SEC_LEVEL in "critical" "high" "medium"; do
29+
echo "====== Processing security_severity_level: $SEC_LEVEL ======"
2930
31+
# ← 关键改动:换成 security_severity_level 参数
3032
ALERTS=$(gh api \
31-
"/repos/$OWNER/$REPO/code-scanning/alerts?severity=$SEVERITY&state=open&per_page=100" \
33+
"/repos/$OWNER/$REPO/code-scanning/alerts?security_severity_level=$SEC_LEVEL&state=open&per_page=100" \
3234
--jq '[.[] | .number]')
3335
3436
COUNT=$(echo $ALERTS | jq 'length')
35-
echo "Found $COUNT alerts with severity: $SEVERITY"
37+
echo "Found $COUNT alerts with security_severity_level: $SEC_LEVEL"
3638
3739
if [ "$COUNT" -eq 0 ]; then
3840
continue
3941
fi
4042
4143
for NUMBER in $(echo $ALERTS | jq -r '.[]'); do
42-
echo "--- Alert #$NUMBER ($SEVERITY) ---"
44+
echo "--- Alert #$NUMBER ($SEC_LEVEL) ---"
4345
4446
EXISTING=$(gh api \
4547
/repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER/autofix \
@@ -66,19 +68,17 @@ jobs:
6668
fi
6769
6870
if [ "$EXISTING" = "success" ]; then
69-
BRANCH="autofix/${SEVERITY}/alert-${NUMBER}"
71+
BRANCH="autofix/${SEC_LEVEL}/alert-${NUMBER}"
7072
7173
SHA=$(gh api /repos/$OWNER/$REPO/git/refs/heads/$DEFAULT_BRANCH \
7274
--jq '.object.sha')
7375
74-
# 创建分支
7576
gh api -X POST /repos/$OWNER/$REPO/git/refs \
7677
-f ref="refs/heads/$BRANCH" \
7778
-f sha="$SHA" 2>/dev/null && \
7879
echo "🌿 Created branch: $BRANCH" || \
7980
echo "🌿 Branch already exists: $BRANCH"
8081
81-
# 提交 fix
8282
gh api -X POST \
8383
/repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER/autofix/commits \
8484
-f target_ref="$BRANCH" || {
@@ -87,22 +87,20 @@ jobs:
8787
}
8888
echo "✅ Committed fix to branch: $BRANCH"
8989
90-
# 获取 alert 标题用于 PR 描述
9190
ALERT_TITLE=$(gh api \
9291
/repos/$OWNER/$REPO/code-scanning/alerts/$NUMBER \
9392
--jq '.rule.description')
9493
95-
# 自动创建 PR(Draft 状态,需要你审核后才能 merge)
9694
gh pr create \
9795
--repo "$OWNER/$REPO" \
9896
--base "$DEFAULT_BRANCH" \
9997
--head "$BRANCH" \
10098
--draft \
101-
--title "[Autofix][$SEVERITY] Alert #$NUMBER: $ALERT_TITLE" \
99+
--title "[Autofix][$SEC_LEVEL] Alert #$NUMBER: $ALERT_TITLE" \
102100
--body "## 🤖 Copilot Autofix 自动修复
103101
104102
**Alert ID:** #$NUMBER
105-
**Severity:** $SEVERITY
103+
**Security Severity:** $SEC_LEVEL
106104
**Rule:** $ALERT_TITLE
107105
108106
此 PR 由 Copilot Autofix 自动生成,请审核后再 merge。

0 commit comments

Comments
 (0)