Use updated clients for local (#1355)

Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
Azeem Shaikh 2021-12-03 18:09:04 -05:00 committed by GitHub
parent aed511670f
commit 84d169bf23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -210,22 +210,33 @@ func validateFormat(format string) bool {
} }
} }
func getRepoAccessors(ctx context.Context, uri string, logger *zap.Logger) (clients.Repo, func getRepoAccessors(ctx context.Context, uri string, logger *zap.Logger) (
clients.RepoClient, string, error) { repo clients.Repo,
var repo clients.Repo repoClient clients.RepoClient,
var errLocal error ossFuzzRepoClient clients.RepoClient,
var errGitHub error ciiClient clients.CIIBestPracticesClient,
if repo, errLocal = localdir.MakeLocalDirRepo(uri); errLocal == nil { repoType string,
err error) {
var localRepo, githubRepo clients.Repo
var errLocal, errGitHub error
if localRepo, errLocal = localdir.MakeLocalDirRepo(uri); errLocal == nil {
// Local directory. // Local directory.
return repo, localdir.CreateLocalDirClient(ctx, logger), repoTypeLocal, nil repoType = repoTypeLocal
repo = localRepo
repoClient = localdir.CreateLocalDirClient(ctx, logger)
return
} }
if githubRepo, errGitHub = githubrepo.MakeGithubRepo(uri); errGitHub == nil {
if repo, errGitHub = githubrepo.MakeGithubRepo(uri); errGitHub == nil {
// GitHub URL. // GitHub URL.
return repo, githubrepo.CreateGithubRepoClient(ctx, logger), repoTypeGitHub, nil repoType = repoTypeGitHub
repo = githubRepo
repoClient = githubrepo.CreateGithubRepoClient(ctx, logger)
ciiClient = clients.DefaultCIIBestPracticesClient()
ossFuzzRepoClient, err = githubrepo.CreateOssFuzzRepoClient(ctx, logger)
return
} }
return nil, nil, "", err = sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unspported URI: %s: [%v, %v]", uri, errLocal, errGitHub))
sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unspported URI: %s: [%v, %v]", uri, errLocal, errGitHub)) return
} }
func getURI(repo, local string) (string, error) { func getURI(repo, local string) (string, error) {
@ -313,18 +324,14 @@ var rootCmd = &cobra.Command{
// nolint // nolint
defer logger.Sync() // Flushes buffer, if any. defer logger.Sync() // Flushes buffer, if any.
repoURI, repoClient, repoType, err := getRepoAccessors(ctx, uri, logger) repoURI, repoClient, ossFuzzRepoClient, ciiClient, repoType, err := getRepoAccessors(ctx, uri, logger)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer repoClient.Close() defer repoClient.Close()
if ossFuzzRepoClient != nil {
ciiClient := clients.DefaultCIIBestPracticesClient() defer ossFuzzRepoClient.Close()
ossFuzzRepoClient, err := githubrepo.CreateOssFuzzRepoClient(ctx, logger)
if err != nil {
log.Fatal(err)
} }
defer ossFuzzRepoClient.Close()
// Read docs. // Read docs.
checkDocs, err := docs.Read() checkDocs, err := docs.Read()