Skip to content

Commit

Permalink
switch maintained check off logfindings and delete it
Browse files Browse the repository at this point in the history
Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock committed Apr 9, 2024
1 parent 7c3403c commit 1bb69eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 82 deletions.
22 changes: 1 addition & 21 deletions checker/check_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,7 @@ func CreateRuntimeErrorResult(name string, e error) CheckResult {
}
}

// LogFindings logs the list of findings.
func LogFindings(findings []finding.Finding, dl DetailLogger) {
for i := range findings {
f := &findings[i]
switch f.Outcome {
case finding.OutcomeFalse:
dl.Warn(&LogMessage{
Finding: f,
})
case finding.OutcomeTrue:
dl.Info(&LogMessage{
Finding: f,
})
default:
dl.Debug(&LogMessage{
Finding: f,
})
}
}
}

// LogFinding logs the given finding at the given level.
func LogFinding(dl DetailLogger, f *finding.Finding, level DetailType) {
lm := LogMessage{Finding: f}
switch level {
Expand Down
30 changes: 0 additions & 30 deletions checks/evaluation/finding.go

This file was deleted.

52 changes: 22 additions & 30 deletions checks/evaluation/maintained.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,15 @@ func Maintained(name string,
return checker.CreateRuntimeErrorResult(name, e)
}

if projectIsArchived(findings) {
checker.LogFindings(falseFindings(findings), dl)
return checker.CreateMinScoreResult(name, "project is archived")
}

if projectWasCreatedInLast90Days(findings) {
checker.LogFindings(falseFindings(findings), dl)
return checker.CreateMinScoreResult(name, "project was created in last 90 days. please review its contents carefully")
}
var archived, recentlyCreated bool

var commitsWithinThreshold, numberOfIssuesUpdatedWithinThreshold int
var err error
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomeTrue {
// currently this works but when we switch notArchived for #3654 this will need to also check the probe
switch f.Outcome {
case finding.OutcomeTrue:
switch f.Probe {
case issueActivityByProjectMember.Probe:
numberOfIssuesUpdatedWithinThreshold, err = strconv.Atoi(f.Values[issueActivityByProjectMember.NumIssuesKey])
Expand All @@ -77,31 +71,29 @@ func Maintained(name string,
return checker.CreateRuntimeErrorResult(name, sce.WithMessage(sce.ErrScorecardInternal, err.Error()))
}
}
case finding.OutcomeFalse:
switch f.Probe {
case notArchived.Probe:
archived = true
case notCreatedRecently.Probe:
recentlyCreated = true

Check warning on line 79 in checks/evaluation/maintained.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/maintained.go#L78-L79

Added lines #L78 - L79 were not covered by tests
}
checker.LogFinding(dl, f, checker.DetailWarn)
default:
checker.LogFinding(dl, f, checker.DetailDebug)

Check warning on line 83 in checks/evaluation/maintained.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/maintained.go#L82-L83

Added lines #L82 - L83 were not covered by tests
}
}

if archived {
return checker.CreateMinScoreResult(name, "project is archived")
}

if recentlyCreated {
return checker.CreateMinScoreResult(name, "project was created in last 90 days. please review its contents carefully")
}

Check warning on line 93 in checks/evaluation/maintained.go

View check run for this annotation

Codecov / codecov/patch

checks/evaluation/maintained.go#L92-L93

Added lines #L92 - L93 were not covered by tests

return checker.CreateProportionalScoreResult(name, fmt.Sprintf(
"%d commit(s) and %d issue activity found in the last %d days",
commitsWithinThreshold, numberOfIssuesUpdatedWithinThreshold, lookBackDays),
commitsWithinThreshold+numberOfIssuesUpdatedWithinThreshold, activityPerWeek*lookBackDays/daysInOneWeek)
}

func projectIsArchived(findings []finding.Finding) bool {
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomeFalse && f.Probe == notArchived.Probe {
return true
}
}
return false
}

func projectWasCreatedInLast90Days(findings []finding.Finding) bool {
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomeFalse && f.Probe == notCreatedRecently.Probe {
return true
}
}
return false
}
5 changes: 4 additions & 1 deletion checks/evaluation/maintained_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ func TestMaintained(t *testing.T) {
{
Probe: hasRecentCommits.Probe,
Outcome: finding.OutcomeFalse,
Message: "no recent commits",
}, {
Probe: issueActivityByProjectMember.Probe,
Outcome: finding.OutcomeFalse,
Message: "no recent issues",
}, {
Probe: notArchived.Probe,
Outcome: finding.OutcomeTrue,
Expand All @@ -77,7 +79,8 @@ func TestMaintained(t *testing.T) {
},
},
result: scut.TestReturn{
Score: 0,
Score: 0,
NumberOfWarn: 2,
},
},
{
Expand Down

0 comments on commit 1bb69eb

Please sign in to comment.