Skip to content

Commit

Permalink
Use singleton pattern for OSS-Fuzz (#902)
Browse files Browse the repository at this point in the history
Co-authored-by: Azeem Shaikh <azeems@google.com>
  • Loading branch information
azeemshaikh38 and azeemsgoogle authored Aug 25, 2021
1 parent 41d0ce3 commit 8cf95c4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions checks/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package checks

import (
"fmt"
"sync"

"github.com/ossf/scorecard/v2/checker"
"github.com/ossf/scorecard/v2/clients"
Expand All @@ -26,16 +27,25 @@ import (
// CheckFuzzing is the registered name for Fuzzing.
const CheckFuzzing = "Fuzzing"

var (
ossFuzzRepo clients.RepoClient
errOssFuzzRepo error
once sync.Once
)

//nolint:gochecknoinits
func init() {
registerCheck(CheckFuzzing, Fuzzing)
}

// Fuzzing runs Fuzzing check.
func Fuzzing(c *checker.CheckRequest) checker.CheckResult {
ossFuzzRepo := githubrepo.CreateGithubRepoClient(c.Ctx, c.Client, c.GraphClient)
if err := ossFuzzRepo.InitRepo("google", "oss-fuzz"); err != nil {
e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("InitRepo: %v", err))
once.Do(func() {
ossFuzzRepo = githubrepo.CreateGithubRepoClient(c.Ctx, c.Client, c.GraphClient)
errOssFuzzRepo = ossFuzzRepo.InitRepo("google", "oss-fuzz")
})
if errOssFuzzRepo != nil {
e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("InitRepo: %v", errOssFuzzRepo))
return checker.CreateRuntimeErrorResult(CheckFuzzing, e)
}

Expand Down

0 comments on commit 8cf95c4

Please sign in to comment.