JenkinsでInspectCodeの結果をいい感じにGitHubにコメントする

JetBrainsのInspectCodeめちゃくちゃ便利なんですが、
結果の出力形式がSARIFに変わってからパースがめんどいな〜と思っていたのでこんな感じにしてみました。

JenkinsFile.groovy
powershell """
  dotnet jb inspectcode Unity.sln `
    --build --severity=WARNING `
    --output=InspectCode.json
"""

def sarif = readJSON file: 'InspectCode.json'
def comments = []
sarif.runs[0].results.each { res ->
    def message = res.message.text
    def level = res.level
    res.locations.each { loc ->
        def path = loc.physicalLocation.artifactLocation.uri
        def line = loc.physicalLocation.region.startLine
        comments << "${path}:${line} [${level}] ${message}"
    }
}

if (comments.size() > 0) {
    pullRequest.comment(":x: InspectCode Failure...\n\n```\n" + comments.join('\n') + "\n```")
}