一键导入
sonar
SonarQube 代码质量平台操作。用于:(1) 查询代码质量报告 (2) 分析项目质量 gate 状态 (3) 管理质量规则 (4) 查看代码热点和漏洞
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
SonarQube 代码质量平台操作。用于:(1) 查询代码质量报告 (2) 分析项目质量 gate 状态 (3) 管理质量规则 (4) 查看代码热点和漏洞
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
GitHub 操作。用于:(1) 管理 GitHub 仓库 (2) 操作 Pull Request (3) 触发 Actions (4) 管理文件和代码 (5) 管理 Issue
⚠️ 需要 ZADIG_API_URL + ZADIG_API_KEY | Zadig DevOps 平台 API 客户端
Apache Apisix API 网关操作。用于:(1) 管理 Apisix 路由 (2) 配置上游和服务 (3) 管理插件 (4) 流量管理和灰度发布。环境变量:APISIX_URL, APISIX_ADMIN_KEY
GitLab 操作。用于:(1) 管理 GitLab 项目和仓库 (2) 操作 Merge Request (3) 触发 CI/CD Pipeline (4) 管理文件和代码 (5) 管理用户和权限
Grafana 可视化和监控操作。用于:(1) 查询 Grafana 指标数据 (2) 管理仪表盘和数据源 (3) 创建和编辑图表 (4) 告警配置
Jenkins CI/CD 操作。用于:(1) 触发 Jenkins 任务构建 (2) 查询任务状态和构建历史 (3) 获取构建日志 (4) 操作 Jenkins 节点和配置
| name | sonar |
| description | SonarQube 代码质量平台操作。用于:(1) 查询代码质量报告 (2) 分析项目质量 gate 状态 (3) 管理质量规则 (4) 查看代码热点和漏洞 |
# ~/.openclaw/workspace/.env
SONAR_URL=http://sonar.example.com:9000
SONAR_TOKEN=your-sonar-token
注意: SonarQube 9.0+ 使用 token 作为用户名,密码为空:
# 认证方式: username=token, password为空
curl -u "$SONAR_TOKEN:" "$SONAR_URL/api/projects/search"
source ~/.openclaw/workspace/.env
source ~/.openclaw/workspace/.env
# 获取项目列表
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/projects/search?projects=PROJECT_KEY"
# 获取项目质量数据
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/measures/component?component=PROJECT_KEY&metricKeys=bugs,vulnerabilities,code_smells,coverage"
source ~/.openclaw/workspace/.env
# 获取项目的 Quality Gate 状态
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/qualitygates/project_status?project=PROJECT_KEY"
# 响应示例
# {
# "projectStatus": {
# "status": "OK", // 或 "ERROR", "WARN"
# "conditions": [
# {"metric": "new_bugs", "status": "OK", "threshold": "0"},
# {"metric": "new_vulnerabilities", "status": "ERROR", ...}
# ]
# }
# }
source ~/.openclaw/workspace/.env
# 获取 Issues
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/issues/search?projects=PROJECT_KEY&status=OPEN&types=BUG"
# 获取代码热点(Hotspots)
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/hotspots/search?project=PROJECT_KEY"
source ~/.openclaw/workspace/.env
# 获取所有度量指标
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/metrics/search"
# 获取代码行数
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/measures/component?component=PROJECT_KEY&metricKeys=ncloc,lines"
source ~/.openclaw/workspace/.env
# 通过 Sonar Scanner 触发扫描
sonar-scanner \
-Dsonar.projectKey=PROJECT_KEY \
-Dsonar.sources=./src \
-Dsonar.host.url=$SONAR_URL \
-Dsonar.token=$SONAR_TOKEN
source ~/.openclaw/workspace/.env
# 创建 Webhook(管理员)
curl -X POST -u "$SONAR_TOKEN:" \
-H "Content-Type: application/json" \
"$SONAR_URL/api/webhooks/create" \
-d '{
"name": "CI Webhook",
"url": "https://your-callback.com/sonar",
"secret": "optional-secret"
}'
在部署前检查代码质量是否达标:
source ~/.openclaw/workspace/.env
# 获取质量 gate 状态
GATE_STATUS=$(curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/qualitygates/project_status?project=my-app" | \
jq -r '.projectStatus.status')
if [ "$GATE_STATUS" != "OK" ]; then
echo "质量门禁未通过!"
# 获取失败原因
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/qualitygates/project_status?project=my-app" | \
jq '.projectStatus.conditions[] | select(.status != "OK")'
exit 1
fi
echo "质量检查通过,可以部署"
获取项目代码度量:
source ~/.openclaw/workspace/.env
# 获取关键指标
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/measures/component?component=my-app&metricKeys=bugs,vulnerabilities,code_smells,coverage,duplicated_lines_density" | \
jq '.component.measures[] | {metric: .metric, value: .value}'
获取需要修复的问题列表:
source ~/.openclaw/workspace/.env
# 获取新出现的 Bug
curl -s -u "$SONAR_TOKEN:" \
"$SONAR_URL/api/issues/search?projects=my-app&types=BUG&status=OPEN&sinceLeakPeriod=true" | \
jq '.issues[] | {key: .key, message: .message, file: .component}'
| API | 说明 |
|---|---|
/api/projects/search | 项目列表 |
/api/qualitygates/project_status | 质量 gate 状态 |
/api/issues/search | 问题列表 |
/api/measures/component | 代码度量 |
/api/hotspots/search | 安全热点 |