【发布时间】:2018-02-15 19:55:47
【问题描述】:
我想使用 SonarQube 分析对我的项目提出的任何拉取请求 (PR)。
几个要点:
- 我的项目托管在 Github 上,它是公开的,是用 C# 编写的,我使用 Appveyor 进行持续集成 (CI);
- 我正在使用SonarCloud(SonarQube 的公共实例)进行代码质量检查,它已经在分析内部 PR(即从主存储库生成的 PR,例如,将
dev分支合并到master分支上); - 我希望它可以分析外部 PR(即,由我的项目的任意分支生成的 PR),这可以使用 SonarQube Github plugin;
- 最重要的是:我不会将我的 API 密钥放在任何公共文件上,Appveyor 也不会在公共 PR 上公开我的安全令牌。
鉴于这些要点,这就是我所做的:
- 创建了一个机器人并授予它对我的仓库的写入权限(如here 所述);
- 在sonarcloud 和
Administration -> Settings -> Pull Requests (Alpha)下,我使用机器人的令牌设置Authentication token,并使用<Organization>/<Repo>格式的我的回购地址设置Repository identifier; - 更新我的项目的
appveyor.yml文件,以便在所有 PR 上运行 SonarQube 分析;类似于以下内容:
build_script:
choco install "msbuild-sonarqube-runner" -y
MSBuild.SonarQube.Runner.exe begin /k:"REPO" /o:"ORGANIZATION" /d:"sonar.host.url=https://sonarcloud.io" /d:"sonar.analysis.mode=preview"
MSBuild.exe /t:Rebuild
MSBuild.SonarQube.Runner.exe end
但是,我仍然没有看到 SonarQube 使用机器人来评论新的 PR(类似于 their demo。
【问题讨论】:
标签: c# github sonarqube pull-request sonar-runner