Add score to SARIF for all results (#1694)

* add score

* fix unit tests
This commit is contained in:
laurentsimon 2022-03-02 17:06:47 -08:00 committed by GitHub
parent 3818dbe839
commit d192c8e3ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 16 deletions

View File

@ -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)
}
}

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -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": [
{

View File

@ -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": [
{