MCPcopy
hub / github.com/ossf/scorecard / Run

Function Run

probes/runsStatusChecksBeforeMerging/impl.go:40–82  ·  view source on GitHub ↗
(raw *checker.RawResults)

Source from the content-addressed store, hash-verified

38)
39
40func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
41 if raw == nil {
42 return nil, "", fmt.Errorf("%w: raw", uerror.ErrNil)
43 }
44
45 r := raw.BranchProtectionResults
46 var findings []finding.Finding
47
48 if len(r.Branches) == 0 {
49 f, err := finding.NewWith(fs, Probe, "no branches found", nil, finding.OutcomeNotApplicable)
50 if err != nil {
51 return nil, Probe, fmt.Errorf("create finding: %w", err)
52 }
53 findings = append(findings, *f)
54 return findings, Probe, nil
55 }
56
57 for i := range r.Branches {
58 branch := &r.Branches[i]
59 var f *finding.Finding
60 var err error
61
62 switch {
63 case len(branch.BranchProtectionRule.CheckRules.Contexts) > 0:
64 f, err = finding.NewWith(fs, Probe,
65 fmt.Sprintf("status check found to merge onto on branch '%s'", *branch.Name), nil,
66 finding.OutcomeTrue)
67 if err != nil {
68 return nil, Probe, fmt.Errorf("create finding: %w", err)
69 }
70 default:
71 f, err = finding.NewWith(fs, Probe,
72 fmt.Sprintf("no status checks found to merge onto branch '%s'", *branch.Name), nil,
73 finding.OutcomeFalse)
74 if err != nil {
75 return nil, Probe, fmt.Errorf("create finding: %w", err)
76 }
77 }
78 f = f.WithValue(BranchNameKey, *branch.Name)
79 findings = append(findings, *f)
80 }
81 return findings, Probe, nil
82}

Callers 1

Test_RunFunction · 0.70

Calls 2

WithValueMethod · 0.95
NewWithFunction · 0.92

Tested by 1

Test_RunFunction · 0.56