From cc974423bbc203d018e671823cbdf727efb8e8d2 Mon Sep 17 00:00:00 2001 From: Spencer Schrock Date: Wed, 24 Apr 2024 11:30:37 -0700 Subject: [PATCH] foo! Signed-off-by: Spencer Schrock --- probes/entries.go | 5 ++++- probes/foo/def.yml | 27 +++++++++++++++++++++++ probes/foo/impl.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 probes/foo/def.yml create mode 100644 probes/foo/impl.go diff --git a/probes/entries.go b/probes/entries.go index ea6bdf43fd4..b1aef39a76d 100644 --- a/probes/entries.go +++ b/probes/entries.go @@ -28,6 +28,7 @@ import ( "github.com/ossf/scorecard/v5/probes/createdRecently" "github.com/ossf/scorecard/v5/probes/dependencyUpdateToolConfigured" "github.com/ossf/scorecard/v5/probes/dismissesStaleReviews" + "github.com/ossf/scorecard/v5/probes/foo" "github.com/ossf/scorecard/v5/probes/fuzzed" "github.com/ossf/scorecard/v5/probes/hasBinaryArtifacts" "github.com/ossf/scorecard/v5/probes/hasDangerousWorkflowScriptInjection" @@ -165,7 +166,9 @@ var ( } // Probes which don't use pre-computed raw data but rather collect it themselves. - Independent = []IndependentProbeImpl{} + Independent = []IndependentProbeImpl{ + foo.Run, + } ) //nolint:gochecknoinits diff --git a/probes/foo/def.yml b/probes/foo/def.yml new file mode 100644 index 00000000000..1e1723dd16a --- /dev/null +++ b/probes/foo/def.yml @@ -0,0 +1,27 @@ +# Copyright 2024 OpenSSF Scorecard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +id: foo +short: foo +motivation: > + foo +implementation: > + believe it or not, foo. +outcome: + - foo! +remediation: + onOutcome: False + effort: Low + text: + - foo? diff --git a/probes/foo/impl.go b/probes/foo/impl.go new file mode 100644 index 00000000000..a70cb20adb0 --- /dev/null +++ b/probes/foo/impl.go @@ -0,0 +1,55 @@ +// Copyright 2024 OpenSSF Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package foo + +import ( + "embed" + "fmt" + + "github.com/ossf/scorecard/v5/checker" + "github.com/ossf/scorecard/v5/finding" + "github.com/ossf/scorecard/v5/internal/probes" + "github.com/ossf/scorecard/v5/probes/internal/utils/uerror" +) + +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) + } + f, err := finding.New(fs, Probe) + if err != nil { + return nil, Probe, fmt.Errorf("create finding: %w", err) + } + if name == "foo" { + f.WithMessage("foo!").WithOutcome(finding.OutcomeTrue) + } else { + f.WithMessage("not foo!!").WithOutcome(finding.OutcomeFalse) + } + return []finding.Finding{*f}, Probe, nil +}