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

✨ allow probes to collect their own data from repo clients #4052

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

spencerschrock
Copy link
Member

What kind of change does this PR introduce?

feature

What is the current behavior?

probes must have the data they rely on in some check's raw result

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

  • introduce "independent" probes which fetch data directly from the repo client
  • Allow these probes to run when specified via --probe
    • since this is only for probes which don't belong to checks, the logic around running probes from the various check/*.go functions doesn't need modified
  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

Fixes #3235

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.)

NONE

rather than rely on checks collecting raw data, independent probes
collect their own raw data using the underlying repo client present in
the check request.

Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
@spencerschrock spencerschrock requested a review from a team as a code owner April 24, 2024 20:22
@spencerschrock spencerschrock requested review from raghavkaul and removed request for a team April 24, 2024 20:22
@spencerschrock
Copy link
Member Author

spencerschrock commented Apr 24, 2024

You can see an example of a toy probe which does its own data collection here.

func init() {
	probes.MustRegisterIndependent(Probe, Run)
}

//go:embed *.yml
var fs embed.FS

const Probe = "foo"

func Run(cr *checker.CheckRequest) ([]finding.Finding, string, error) {
	if cr == nil {
		return nil, "", fmt.Errorf("%w: check request", uerror.ErrNil)
	}

	name, err := cr.RepoClient.GetDefaultBranchName()
	if err != nil {
		return nil, Probe, fmt.Errorf("fetching default branch name: %w", err)
	}

	// ...
}

Which works as expected:

go run main.go --repo ossf/scorecard --probes foo --format probe | jq
{
  "date": "2024-04-24",
  "repo": {
    "name": "github.com/ossf/scorecard",
    "commit": "43022835f28208561e72b9ffbdc95aa8dfc35421"
  },
  "scorecard": {
    "version": "devel",
    "commit": "unknown"
  },
  "findings": [
    {
      "remediation": {
        "text": "foo?",
        "markdown": "",
        "effort": 1
      },
      "probe": "foo",
      "message": "not foo!!",
      "outcome": "False"
    }
  ]
}

@spencerschrock spencerschrock enabled auto-merge (squash) April 25, 2024 18:14
@spencerschrock spencerschrock merged commit 71aed95 into ossf:main Apr 25, 2024
36 checks passed
@spencerschrock spencerschrock deleted the probe-check-request branch April 25, 2024 18:23
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.

Discussion: Can probes exist without belonging to a check
2 participants