1515package raw
1616
1717import (
18- "errors"
1918 "fmt"
2019
2120 "github.com/ossf/scorecard/v4/checker"
2221 "github.com/ossf/scorecard/v4/clients"
2322)
2423
25- var errNoCommitFound = errors .New ("no commit found" )
26-
2724// Vulnerabilities retrieves the raw data for the Vulnerabilities check.
2825func Vulnerabilities (c * checker.CheckRequest ) (checker.VulnerabilitiesData , error ) {
2926 commits , err := c .RepoClient .ListCommits ()
3027 if err != nil {
3128 return checker.VulnerabilitiesData {}, fmt .Errorf ("repoClient.ListCommits: %w" , err )
3229 }
3330
34- if len (commits ) < 1 || commits [ 0 ]. SHA == "" {
35- return checker.VulnerabilitiesData {}, fmt . Errorf ( "%w" , errNoCommitFound )
31+ if len (commits ) < 1 || allOf ( commits , hasEmptySHA ) {
32+ return checker.VulnerabilitiesData {}, nil
3633 }
3734
3835 resp , err := c .VulnerabilitiesClient .HasUnfixedVulnerabilities (c .Ctx , commits [0 ].SHA )
@@ -52,6 +49,21 @@ func Vulnerabilities(c *checker.CheckRequest) (checker.VulnerabilitiesData, erro
5249 return checker.VulnerabilitiesData {Vulnerabilities : vulns }, nil
5350}
5451
52+ type predicateOnCommitFn func (clients.Commit ) bool
53+
54+ var hasEmptySHA predicateOnCommitFn = func (c clients.Commit ) bool {
55+ return c .SHA == ""
56+ }
57+
58+ func allOf (commits []clients.Commit , predicate func (clients.Commit ) bool ) bool {
59+ for i := range commits {
60+ if ! predicate (commits [i ]) {
61+ return false
62+ }
63+ }
64+ return true
65+ }
66+
5567func getVulnerabilities (resp * clients.VulnerabilitiesResponse ) []string {
5668 ids := make ([]string , 0 , len (resp .Vulns ))
5769 for _ , vuln := range resp .Vulns {
0 commit comments