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

Function Run

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

Source from the content-addressed store, hash-verified

42)
43
44func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
45 if raw == nil {
46 return nil, "", fmt.Errorf("%w: raw", uerror.ErrNil)
47 }
48
49 var findings []finding.Finding
50
51 r := raw.MaintainedResults
52 threshold := time.Now().AddDate(0 /*years*/, 0 /*months*/, -1*lookBackDays /*days*/)
53 commitsWithinThreshold := 0
54
55 for i := range r.DefaultBranchCommits {
56 commit := r.DefaultBranchCommits[i]
57 if commit.CommittedDate.After(threshold) {
58 commitsWithinThreshold++
59 }
60 }
61
62 var text string
63 var outcome finding.Outcome
64 if commitsWithinThreshold > 0 {
65 text = "Found a contribution within the threshold."
66 outcome = finding.OutcomeTrue
67 } else {
68 text = "Did not find contribution within the threshold."
69 outcome = finding.OutcomeFalse
70 }
71 f, err := finding.NewWith(fs, Probe, text, nil, outcome)
72 if err != nil {
73 return nil, Probe, fmt.Errorf("create finding: %w", err)
74 }
75 f = f.WithValues(map[string]string{
76 NumCommitsKey: strconv.Itoa(commitsWithinThreshold),
77 LookbackDayKey: strconv.Itoa(lookBackDays),
78 })
79 findings = append(findings, *f)
80
81 return findings, Probe, nil
82}

Callers 1

Test_RunFunction · 0.70

Calls 2

NewWithFunction · 0.92
WithValuesMethod · 0.80

Tested by 1

Test_RunFunction · 0.56