GeekFactory

int128.hatenablog.com

SonarQube GitHub PluginをGitBucketで使用する(失敗)

SonarQube GitHub Pluginを使うと、静的解析の結果をPull Requestのステータスやコメントに反映できます。この便利な機能がGitBucketでも使えるか試してみましたが、残念ながら無理でした。何かの知見になればと残しておきます。

プラグインはPull Requestで変更されたファイルに対してのみ静的解析を行うようです。

How To Configure SonarQube GitHub Plugin With Jenkins - Stack Overflow

The analysis is automatically filtered based on the files in the pull request. We were testing with pull requests that only had changes in pom.xml and readme files. Once a functional change was introduced, everything lit up on the GitHub Pull Request view as expected.

プラグインはPull Requestで変更されたファイルを取得するため、以下のAPIを利用します。

https://developer.github.com/v3/pulls/#list-pull-requests-files

このAPIはGitBucketでは未実装(404が返される)のため、エラーになります。Gradle SonarQube Pluginを利用している場合はデバッグレベルで実行すると以下のようなログを確認できます。

21:15:42.972 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@5144a1927 pairs: {GET /api/v3/repos/example/hello/pulls/73/comments HTTP/1.1: null}{Authorization: token ****}{Accept-Encoding: gzip}{User-Agent: Java/1.8.0_102}{Host: git.example.com}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
21:15:43.037 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@43fbb6477 pairs: {GET /api/v3/repos/example/hello/pulls/73/files HTTP/1.1: null}{Authorization: token ****}{Accept-Encoding: gzip}{User-Agent: Java/1.8.0_102}{Host: git.example.com}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}

今後の機能追加に期待です。Pull Requestの画面ではファイル一覧を表示しているので、APIで返すのはそれほど難しくないかもしれません。