ossf / scorecard

OpenSSF Scorecard - Security health metrics for Open Source
https://scorecard.dev
Apache License 2.0
4.25k stars 460 forks source link

:warning: Simplify RunScorecard with functional optionals #4106

Closed spencerschrock closed 3 weeks ago

spencerschrock commented 1 month ago

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.

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.
spencerschrock commented 1 month ago

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 https://github.com/ossf/scorecard/blob/6815161e15b9acaec08bc868869894dc906e3252/cron/internal/worker/main.go#L202-L207

spencerschrock commented 4 weeks ago

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. https://github.com/ossf/scorecard/blob/438f838d6cb4d59579ef3651d23603e51dc59ae9/pkg/scorecard.go#L382-L399