mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-04 03:52:31 +03:00
✨ Add score to SARIF for all results (#1694)
* add score * fix unit tests
This commit is contained in:
parent
3818dbe839
commit
d192c8e3ac
11
pkg/sarif.go
11
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 `<br>`.
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
2
pkg/testdata/check1.sarif
vendored
2
pkg/testdata/check1.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
2
pkg/testdata/check2.sarif
vendored
2
pkg/testdata/check2.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
4
pkg/testdata/check3.sarif
vendored
4
pkg/testdata/check3.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
4
pkg/testdata/check4.sarif
vendored
4
pkg/testdata/check4.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
2
pkg/testdata/check7.sarif
vendored
2
pkg/testdata/check7.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
12
pkg/testdata/check8.sarif
vendored
12
pkg/testdata/check8.sarif
vendored
@ -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": [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user