Skip to content

Commit

Permalink
pkg/sarif.go: Add score in message (#1593)
Browse files Browse the repository at this point in the history
pkg/testdata/check6.sarif: Update message
  • Loading branch information
laurentsimon authored Feb 2, 2022
1 parent 009aa85 commit 0670b8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,14 @@ func filterOutDetailType(details []checker.CheckDetail, t checker.DetailType) []
return ret
}

func createDefaultLocationMessage(check *checker.CheckResult) string {
func createDefaultLocationMessage(check *checker.CheckResult, score int) string {
details := filterOutDetailType(check.Details2, checker.DetailInfo)
s, b := detailsToString(details, log.WarnLevel)
if b {
// Warning: GitHub UX needs a single `\n` to turn it into a `<br>`.
return fmt.Sprintf("%s:\n%s", check.Reason, s)
return fmt.Sprintf("score is %d: %s:\n%s", score, check.Reason, s)
}
return check.Reason
return fmt.Sprintf("score is %d: %s", score, check.Reason)
}

// AsSARIF outputs ScorecardResult in SARIF 2.1.0 format.
Expand Down Expand Up @@ -597,7 +597,7 @@ func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel log.Level,
// Note: this is not a valid URI but GitHub still accepts it.
// See https://sarifweb.azurewebsites.net/Validation to test verification.
locs = addDefaultLocation(locs, "no file associated with this alert")
msg := createDefaultLocationMessage(&check)
msg := createDefaultLocationMessage(&check, check.Score)
cr := createSARIFCheckResult(RuleIndex, sarifCheckID, msg, &locs[0])
run.Results = append(run.Results, cr)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testdata/check6.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ruleId": "CheckNameID",
"ruleIndex": 0,
"message": {
"text": "six score reason:\nWarn: warn message\nClick Remediation section below to solve this issue"
"text": "score is 6: six score reason:\nWarn: warn message\nClick Remediation section below to solve this issue"
},
"locations": [
{
Expand Down

0 comments on commit 0670b8b

Please sign in to comment.