diff --git a/pkg/sarif.go b/pkg/sarif.go index f1ebd4c6..1332a796 100644 --- a/pkg/sarif.go +++ b/pkg/sarif.go @@ -510,14 +510,18 @@ func filterOutDetailType(details []checker.CheckDetail, t checker.DetailType) [] return ret } +func messageWithScore(msg string, score int) string { + return fmt.Sprintf("score is %d: %s", score, msg) +} + 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 `
`. - return fmt.Sprintf("score is %d: %s:\n%s", score, check.Reason, s) + return messageWithScore(fmt.Sprintf("%s:\n%s", check.Reason, s), score) } - return fmt.Sprintf("score is %d: %s", score, check.Reason) + return messageWithScore(check.Reason, score) } // AsSARIF outputs ScorecardResult in SARIF 2.1.0 format. @@ -603,7 +607,8 @@ func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel log.Level, } else { for _, loc := range locs { // Use the location's message (check's detail's message) as message. - cr := createSARIFCheckResult(RuleIndex, sarifCheckID, loc.Message.Text, &loc) + msg := messageWithScore(loc.Message.Text, check.Score) + cr := createSARIFCheckResult(RuleIndex, sarifCheckID, msg, &loc) run.Results = append(run.Results, cr) } } diff --git a/pkg/testdata/check1.sarif b/pkg/testdata/check1.sarif index 3e15284b..e534414b 100644 --- a/pkg/testdata/check1.sarif +++ b/pkg/testdata/check1.sarif @@ -47,7 +47,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 5: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { diff --git a/pkg/testdata/check2.sarif b/pkg/testdata/check2.sarif index da488ef0..e258ffe3 100644 --- a/pkg/testdata/check2.sarif +++ b/pkg/testdata/check2.sarif @@ -47,7 +47,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { diff --git a/pkg/testdata/check3.sarif b/pkg/testdata/check3.sarif index d35b3eb3..89dd0dec 100644 --- a/pkg/testdata/check3.sarif +++ b/pkg/testdata/check3.sarif @@ -104,7 +104,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -128,7 +128,7 @@ "ruleId": "CheckName2ID", "ruleIndex": 1, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { diff --git a/pkg/testdata/check4.sarif b/pkg/testdata/check4.sarif index d35b3eb3..89dd0dec 100644 --- a/pkg/testdata/check4.sarif +++ b/pkg/testdata/check4.sarif @@ -104,7 +104,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -128,7 +128,7 @@ "ruleId": "CheckName2ID", "ruleIndex": 1, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { diff --git a/pkg/testdata/check7.sarif b/pkg/testdata/check7.sarif index b05186b4..1cda7df9 100644 --- a/pkg/testdata/check7.sarif +++ b/pkg/testdata/check7.sarif @@ -104,7 +104,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 0: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { diff --git a/pkg/testdata/check8.sarif b/pkg/testdata/check8.sarif index cfa7e185..82924a1d 100644 --- a/pkg/testdata/check8.sarif +++ b/pkg/testdata/check8.sarif @@ -76,7 +76,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 5: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -103,7 +103,7 @@ "ruleId": "CheckNameID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 5: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -130,7 +130,7 @@ "ruleId": "CheckName5ID", "ruleIndex": 1, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 8: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -157,7 +157,7 @@ "ruleId": "CheckName5ID", "ruleIndex": 1, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 8: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -229,7 +229,7 @@ "ruleId": "CheckName6ID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 9: warn message\nClick Remediation section below to solve this issue" }, "locations": [ { @@ -301,7 +301,7 @@ "ruleId": "CheckName4ID", "ruleIndex": 0, "message": { - "text": "warn message\nClick Remediation section below to solve this issue" + "text": "score is 5: warn message\nClick Remediation section below to solve this issue" }, "locations": [ {