Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Remove ErrRepoUnavailable #908

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions checks/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import (
"strings"

"github.com/ossf/scorecard/v2/checker"
"github.com/ossf/scorecard/v2/clients"
"github.com/ossf/scorecard/v2/clients/githubrepo"
sce "github.com/ossf/scorecard/v2/errors"
)

var errIgnore *clients.ErrRepoUnavailable

// CheckSecurityPolicy is the registred name for SecurityPolicy.
const CheckSecurityPolicy = "Security-Policy"

Expand Down Expand Up @@ -105,7 +103,7 @@ func SecurityPolicy(c *checker.CheckRequest) checker.CheckResult {
if r {
return checker.CreateMaxScoreResult(CheckSecurityPolicy, "security policy file detected")
}
case !errors.Is(err, errIgnore):
case !errors.Is(err, sce.ErrRepoUnreachable):
return checker.CreateRuntimeErrorResult(CheckSecurityPolicy, err)
}
return checker.CreateMinScoreResult(CheckSecurityPolicy, "security policy file not detected")
Expand Down
3 changes: 2 additions & 1 deletion clients/githubrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/shurcooL/githubv4"

"github.com/ossf/scorecard/v2/clients"
sce "github.com/ossf/scorecard/v2/errors"
)

// Client is GitHub-specific implementation of RepoClient.
Expand All @@ -44,7 +45,7 @@ func (client *Client) InitRepo(owner, repoName string) error {
repo, _, err := client.repoClient.Repositories.Get(client.ctx, owner, repoName)
if err != nil {
// nolint: wrapcheck
return clients.NewRepoUnavailableError(err)
return sce.Create(sce.ErrRepoUnreachable, err.Error())
}
client.repo = repo
client.owner = repo.Owner.GetLogin()
Expand Down
27 changes: 0 additions & 27 deletions clients/repo_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@
// Package clients defines the interface for RepoClient and related structs.
package clients

import (
"fmt"
)

// ErrRepoUnavailable is returned when RepoClient is unable to reach the repo.
// UPGRADEv2: use ErrRepoUnreachable instead.
type ErrRepoUnavailable struct {
innerError error
}

// Error returns the error string.
func (e *ErrRepoUnavailable) Error() string {
return fmt.Sprintf("repo cannot be accessed: %v", e.innerError)
}

// Unwrap returns the wrapped error.
func (e *ErrRepoUnavailable) Unwrap() error {
return e.innerError
}

// NewRepoUnavailableError returns a wrapped error of type ErrRepoUnavailable.
func NewRepoUnavailableError(err error) error {
return &ErrRepoUnavailable{
innerError: err,
}
}

// RepoClient interface is used by Scorecard checks to access a repo.
type RepoClient interface {
InitRepo(owner, repo string) error
Expand Down
7 changes: 2 additions & 5 deletions cron/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ import (
"github.com/ossf/scorecard/v2/stats"
)

var (
ignoreRuntimeErrors = flag.Bool("ignoreRuntimeErrors", false, "if set to true any runtime errors will be ignored")
errIgnore *clients.ErrRepoUnavailable
)
var ignoreRuntimeErrors = flag.Bool("ignoreRuntimeErrors", false, "if set to true any runtime errors will be ignored")

func processRequest(ctx context.Context,
batchRequest *data.ScorecardBatchRequest, checksToRun checker.CheckNameToFnMap,
Expand Down Expand Up @@ -95,7 +92,7 @@ func processRequest(ctx context.Context,
for _, repoURL := range repoURLs {
log.Printf("Running Scorecard for repo: %s", repoURL.URL())
result, err := pkg.RunScorecards(ctx, repoURL, checksToRun, repoClient, httpClient, githubClient, graphClient)
if errors.Is(err, errIgnore) {
if errors.Is(err, sce.ErrRepoUnreachable) {
// Not accessible repo - continue.
continue
}
Expand Down