88 create_issue :
99 runs-on : ubuntu-latest
1010 permissions :
11- issues : write
11+ issues : write
1212 steps :
1313 - name : Create GitHub Issue
1414 uses : actions/github-script@v9
1515 with :
1616 script : |
1717 const alert = context.payload.alert;
1818
19- // 组装 Issue 的标题和内容
20- const issueTitle = `[安全扫描] ${alert.rule.description}`;
19+ // 1. 获取当前警报的严重级别 (转成小写以防大小写不统一)
20+ const severity = (alert.rule.security_severity_level || alert.rule.severity || 'unknown').toLowerCase();
21+
22+ // 2. 定义我们允许提 Issue 的白名单级别
23+ // 注意:加入了 'critical' (极高) 以及 'error' (某些规则可能使用这个词)
24+ const allowedSeverities = ['critical', 'high', 'medium', 'error'];
25+
26+ // 3. 拦截:如果当前级别不在白名单里,直接退出脚本,不创建 Issue
27+ if (!allowedSeverities.includes(severity)) {
28+ console.log(`[跳过] 当前漏洞级别为 '${severity}',未达到提 Issue 的标准。`);
29+ return; // 直接 return,后面的代码就不会执行了
30+ }
31+
32+ console.log(`[通过] 发现级别为 '${severity}' 的漏洞,准备创建 Issue...`);
33+
34+ // 4. 组装 Issue 的标题和内容
35+ const issueTitle = `[安全扫描 - ${severity.toUpperCase()}] ${alert.rule.description}`;
2136 const issueBody = `
2237 ### 🚨 CodeQL 发现新的安全警告
2338
2439 **问题类型:** ${alert.rule.name}
25- **严重程度:** ${alert.rule.security_severity_level || alert.rule. severity}
40+ **严重程度:** ${severity.toUpperCase() }
2641 **文件路径:** \`${alert.most_recent_instance.location.path}\`
2742 **代码行数:** 第 ${alert.most_recent_instance.location.start_line} 行
2843
2944 [👉 点击此处查看详细报告与修复建议](${alert.html_url})
3045 `;
3146
32- // 调用 GitHub API 创建 Issue
47+ // 5. 调用 GitHub API 创建 Issue
3348 await github.rest.issues.create({
3449 owner: context.repo.owner,
3550 repo: context.repo.repo,
3651 title: issueTitle,
3752 body: issueBody,
38- labels: ['security', 'bug', 'codeql']
53+ // 根据需要可以打上不同的 tag,比如高危漏洞打个紧急标签
54+ labels: ['security', 'bug', 'codeql', `severity:${severity}`]
3955 });
0 commit comments