Maintained applies the score policy for the Maintained check.
(name string, findings []finding.Finding, dl checker.DetailLogger, )
| 35 | |
| 36 | // Maintained applies the score policy for the Maintained check. |
| 37 | func Maintained(name string, |
| 38 | findings []finding.Finding, dl checker.DetailLogger, |
| 39 | ) checker.CheckResult { |
| 40 | // We have 4 unique probes, each should have a finding. |
| 41 | expectedProbes := []string{ |
| 42 | archived.Probe, |
| 43 | issueActivityByProjectMember.Probe, |
| 44 | hasRecentCommits.Probe, |
| 45 | createdRecently.Probe, |
| 46 | } |
| 47 | |
| 48 | if !finding.UniqueProbesEqual(findings, expectedProbes) { |
| 49 | e := sce.WithMessage(sce.ErrScorecardInternal, "invalid probe results") |
| 50 | return checker.CreateRuntimeErrorResult(name, e) |
| 51 | } |
| 52 | |
| 53 | var isArchived, recentlyCreated bool |
| 54 | |
| 55 | var commitsWithinThreshold, numberOfIssuesUpdatedWithinThreshold int |
| 56 | var err error |
| 57 | for i := range findings { |
| 58 | f := &findings[i] |
| 59 | switch f.Outcome { |
| 60 | case finding.OutcomeTrue: |
| 61 | switch f.Probe { |
| 62 | case issueActivityByProjectMember.Probe: |
| 63 | numberOfIssuesUpdatedWithinThreshold, err = strconv.Atoi(f.Values[issueActivityByProjectMember.NumIssuesKey]) |
| 64 | if err != nil { |
| 65 | return checker.CreateRuntimeErrorResult(name, sce.WithMessage(sce.ErrScorecardInternal, err.Error())) |
| 66 | } |
| 67 | case hasRecentCommits.Probe: |
| 68 | commitsWithinThreshold, err = strconv.Atoi(f.Values[hasRecentCommits.NumCommitsKey]) |
| 69 | if err != nil { |
| 70 | return checker.CreateRuntimeErrorResult(name, sce.WithMessage(sce.ErrScorecardInternal, err.Error())) |
| 71 | } |
| 72 | case archived.Probe: |
| 73 | isArchived = true |
| 74 | checker.LogFinding(dl, f, checker.DetailWarn) |
| 75 | case createdRecently.Probe: |
| 76 | recentlyCreated = true |
| 77 | checker.LogFinding(dl, f, checker.DetailWarn) |
| 78 | } |
| 79 | case finding.OutcomeFalse: |
| 80 | // both archive and created recently are good if false, and the |
| 81 | // other probes are informational and dont need logged. But we need |
| 82 | // to specify the case so it doesn't get logged below at the debug level |
| 83 | default: |
| 84 | checker.LogFinding(dl, f, checker.DetailDebug) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if isArchived { |
| 89 | return checker.CreateMinScoreResult(name, "project is archived") |
| 90 | } |
| 91 | |
| 92 | if recentlyCreated { |
| 93 | return checker.CreateMinScoreResult(name, |
| 94 | "project was created within the last 90 days. Please review its contents carefully") |