mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-19 04:57:14 +03:00
✨ Add details to message for default location in SARIF (#1414)
* add details to message * fix
This commit is contained in:
parent
eef99b5ce0
commit
cf71c9539c
@ -36,6 +36,7 @@ func BinaryArtifacts(name string, dl checker.DetailLogger,
|
||||
for _, f := range r.Files {
|
||||
dl.Warn3(&checker.LogMessage{
|
||||
Path: f.Path, Type: checker.FileTypeBinary,
|
||||
Offset: f.Offset,
|
||||
Text: "binary detected",
|
||||
})
|
||||
// We remove one point for each binary.
|
||||
|
@ -116,7 +116,7 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
|
||||
}
|
||||
|
||||
// Return raw results.
|
||||
return checker.SecurityPolicyData{Files: files}, err
|
||||
return checker.SecurityPolicyData{Files: files}, nil
|
||||
}
|
||||
|
||||
func isSecurityRstFound(name string) bool {
|
||||
|
26
pkg/sarif.go
26
pkg/sarif.go
@ -501,6 +501,28 @@ func createCheckIdentifiers(name string) (string, string) {
|
||||
return name, fmt.Sprintf("%sID", n)
|
||||
}
|
||||
|
||||
func filterOutDetailType(details []checker.CheckDetail, t checker.DetailType) []checker.CheckDetail {
|
||||
ret := make([]checker.CheckDetail, 0)
|
||||
for i := range details {
|
||||
d := details[i]
|
||||
if d.Type == t {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, d)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func createDefaultLocationMessage(check *checker.CheckResult) string {
|
||||
details := filterOutDetailType(check.Details2, checker.DetailInfo)
|
||||
s, b := detailsToString(details, zapcore.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 check.Reason
|
||||
}
|
||||
|
||||
// AsSARIF outputs ScorecardResult in SARIF 2.1.0 format.
|
||||
func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel zapcore.Level,
|
||||
writer io.Writer, checkDocs docs.Doc, policy *spol.ScorecardPolicy) error {
|
||||
@ -576,8 +598,8 @@ func (r *ScorecardResult) AsSARIF(showDetails bool, logLevel zapcore.Level,
|
||||
RuleIndex := len(run.Tool.Driver.Rules) - 1
|
||||
if len(locs) == 0 {
|
||||
locs = addDefaultLocation(locs, "no file available")
|
||||
// Use the `reason` as message.
|
||||
cr := createSARIFCheckResult(RuleIndex, sarifCheckID, check.Reason, &locs[0])
|
||||
msg := createDefaultLocationMessage(&check)
|
||||
cr := createSARIFCheckResult(RuleIndex, sarifCheckID, msg, &locs[0])
|
||||
run.Results = append(run.Results, cr)
|
||||
} else {
|
||||
for _, loc := range locs {
|
||||
|
2
pkg/testdata/check6.sarif
vendored
2
pkg/testdata/check6.sarif
vendored
@ -47,7 +47,7 @@
|
||||
"ruleId": "CheckNameID",
|
||||
"ruleIndex": 0,
|
||||
"message": {
|
||||
"text": "six score reason"
|
||||
"text": "six score reason:\nWarn: warn message"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user