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

⚠️ Simplify RunScorecard with functional optionals #4106

Merged
merged 15 commits into from
Jun 10, 2024

Conversation

spencerschrock
Copy link
Contributor

What kind of change does this PR introduce?

breaking change / refactor

What is the current behavior?

See #3717. Ultimately every change to the signature is another breaking change, and this breaking change hopefully stops future breaking changes.

What is the new behavior (if this is a feature change)?**

A new top level entry point: Run. The hope is that the pkg package also gets renamed so it's just scorecard.Run() instead of pkg.RunScorecard or pkg.Run, but that's not the topic of this PR.

This entry point takes a context and a repo to be analyzed. Everything else is optional and can be passed as a list of WithFoo() arguments.

  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

Fixes #3717

Special notes for your reviewer

Does this PR introduce a user-facing change?

For user-facing changes, please add a concise, human-readable release note to
the release-note

(In particular, describe what changes users might need to make in their
application as a result of this pull request.)

The main function to call Scorecard as a library was changed to reduce future breaking changes.

Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
@spencerschrock
Copy link
Contributor Author

This is still a WIP, as I'm thinking about WithChecks, if that should be a []string or the existing checker.CheckNameToFnMap.

There's also some duplication that happens setting up the CheckNameToFnMap

requiredRequestType := []checker.RequestType{}
if repoReq.GetCommit() != clients.HeadSHA {
commitSHA = repoReq.GetCommit()
requiredRequestType = append(requiredRequestType, checker.CommitBased)
}
checksToRun, err := policy.GetEnabled(nil /*policy*/, nil /*checks*/, requiredRequestType)

Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
@spencerschrock
Copy link
Contributor Author

In order to automatically create a repo client if one isn't provided, I need to be able to test the Repo type.
So my latest changes make the various clients.Repo implementations public.

scorecard/pkg/scorecard.go

Lines 382 to 399 in 438f838

switch repo.(type) {
case *localdir.Repo:
requiredRequestTypes = append(requiredRequestTypes, checker.FileBased)
if c.client == nil {
c.client = localdir.CreateLocalDirClient(ctx, logger)
}
case *githubrepo.Repo:
if c.client == nil {
c.client = githubrepo.CreateGithubRepoClient(ctx, logger)
}
case *gitlabrepo.Repo:
if c.client == nil {
c.client, err = gitlabrepo.CreateGitlabClient(ctx, repo.Host())
if err != nil {
return ScorecardResult{}, fmt.Errorf("creating gitlab client: %w", err)
}
}
}

@spencerschrock spencerschrock marked this pull request as ready for review June 4, 2024 21:50
@spencerschrock spencerschrock requested a review from a team as a code owner June 4, 2024 21:50
@spencerschrock spencerschrock requested review from justaugustus and removed request for a team June 4, 2024 21:50
pkg/scorecard.go Show resolved Hide resolved
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
@spencerschrock spencerschrock merged commit 6d8f701 into ossf:main Jun 10, 2024
36 checks passed
@spencerschrock spencerschrock deleted the optional-api branch June 10, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Redesigning the top-level Scorecard entrypoint
2 participants