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,
clients.RepoClient, string, error) {
var repo clients.Repo
var errLocal error
var errGitHub error
if repo, errLocal = localdir.MakeLocalDirRepo(uri); errLocal == nil {
func getRepoAccessors(ctx context.Context, uri string, logger *zap.Logger) (
repo clients.Repo,
repoClient clients.RepoClient,
ossFuzzRepoClient clients.RepoClient,
ciiClient clients.CIIBestPracticesClient,
repoType string,
err error) {
var localRepo, githubRepo clients.Repo
var errLocal, errGitHub error
if localRepo, errLocal = localdir.MakeLocalDirRepo(uri); errLocal == nil {
// Local directory.
return repo, localdir.CreateLocalDirClient(ctx, logger), repoTypeLocal, nil
repoType = repoTypeLocal
repo = localRepo
repoClient = localdir.CreateLocalDirClient(ctx, logger)
return
}
if repo, errGitHub = githubrepo.MakeGithubRepo(uri); errGitHub == nil {
if githubRepo, errGitHub = githubrepo.MakeGithubRepo(uri); errGitHub == nil {
// 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, "",
sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unspported URI: %s: [%v, %v]", uri, errLocal, errGitHub))
err = sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unspported URI: %s: [%v, %v]", uri, errLocal, errGitHub))
return
}
func getURI(repo, local string) (string, error) {
@ -313,18 +324,14 @@ var rootCmd = &cobra.Command{
// nolint
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 {
log.Fatal(err)
}
defer repoClient.Close()
ciiClient := clients.DefaultCIIBestPracticesClient()
ossFuzzRepoClient, err := githubrepo.CreateOssFuzzRepoClient(ctx, logger)
if err != nil {
log.Fatal(err)
if ossFuzzRepoClient != nil {
defer ossFuzzRepoClient.Close()
}
defer ossFuzzRepoClient.Close()
// Read docs.
checkDocs, err := docs.Read()