| 42 | ) |
| 43 | |
| 44 | func 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 | } |