SuperAPI AI 工具集

gh-code-scanning

通用与其它

查看项目

更新于 10-16 09:32

技能介绍

用途:GitHub 代码扫描告警由 CodeQL、Scorecard 等静态分析工具产生,展示在 GitHub Security 标签页,而默认 MCP 工具集无法访问该页面。本技能提供只读脚本,用于获取并按规则和严重程度分组代码扫描告警。

前置条件:需 PowerShell 7+(来自 learn.microsoft.com/powershell);gh CLI 已安装并在 PATH(来自 cli.github.com);执行 gh auth login 或设置 GH_TOKEN,需要 security_events 权限范围(私有仓库);仅公开仓库需 public_repo;repo 权限范围也可满足 security_events。命令中无需显式传 token,gh CLI 自动处理认证。Get-CodeScanningAlerts.ps1 启动时会校验上述前置条件,失败则中止并给出针对性错误信息。bash 脚本需 jq。

主要能力:Get-CodeScanningAlerts.ps1 按出现次数降序分组并排序开放告警,支持 -Owner、-Repo(必填)、-OutputFormat(程序化消费必须用 Json,GroupedJson 为别名)、-Branch(默认 main)、-IncludeDismissedStillDetected(附加报告仍被检测到的已忽略告警,Kind 为 dismissed-still-detected)。bash 版 get-code-scanning-alerts.sh 参数为 -o、-r、-b、-s(按严重程度过滤)、-d。

用法示例:pwsh scripts/Get-CodeScanningAlerts.ps1 -Owner "{owner}" -Repo "{repo}" -OutputFormat Json;bash scripts/get-code-scanning-alerts.sh -o "{owner}" -r "{repo}"。单一告警详情用 gh api repos/{owner}/{repo}/code-scanning/alerts/{alert_number};分析元数据用 gh api repos/{owner}/{repo}/code-scanning/analyses -f tool_name=CodeQL -f ref=refs/heads/main -f per_page=10。

输出字段:每组含 RuleDescription、RuleId、Tool、SecuritySeverity(代码质量规则为 null)、Severity(error/warning/note/none,始终填充)、Count、AffectedPaths(唯一排序文件路径数组;无关联文件时为 [])、HasFilePaths、AlertUrl、FindingDescription。

适用场景:仅用于读取代码扫描告警;列表与分组只可用该脚本,不得用 gh api 作为回退。仓库可据此创建 backlog issue,创建前用标题及内嵌自动化标记去重。

限制:处置策略要求在代码或配置中修复告警,不得忽略或建议忽略(含误报与测试代码);无法立即修复时由维护者添加带审核期的受控例外,告警保持开放。故障排查见原文:如 gh CLI 未找到、未认证、403 缺少 security_events、空结果(ref 格式错误)、jq 缺失等。分类标识选用 security。