18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rail_verdict/reporters/sarif.rb', line 18
def render(result, findings: nil)
all_findings = findings || result.findings
rules = dedup_rules(all_findings)
results = all_findings.map { |finding| finding_to_result(finding) }.sort_by { |entry| [entry["ruleId"].to_s, entry.dig("locations", 0, "physicalLocation", "artifactLocation", "uri").to_s, entry.dig("locations", 0, "physicalLocation", "region", "startLine").to_i] }
{
"version" => "2.1.0",
"$schema" => "https://json.schemastore.org/sarif-2.1.0.json",
"runs" => [
{
"tool" => {
"driver" => {
"name" => "RailVerdict",
"version" => RailVerdict::VERSION,
"informationUri" => "https://railverdict.dev",
"rules" => rules
}
},
"results" => results,
"invocations" => [
{
"executionSuccessful" => result.completion_status == "complete",
"toolExecutionNotifications" => result.decision_reasons.map { |reason| { "message" => { "text" => reason.fetch("message") }, "level" => "note", "descriptor" => { "id" => reason.fetch("code") } } }
}
]
}
]
}
end
|