diff --git a/checker/check_result.go b/checker/check_result.go index cbb4cb90878..c600c1e7005 100644 --- a/checker/check_result.go +++ b/checker/check_result.go @@ -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 { diff --git a/checks/evaluation/finding.go b/checks/evaluation/finding.go deleted file mode 100644 index 24aaf4a0d07..00000000000 --- a/checks/evaluation/finding.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2023 OpenSSF Scorecard Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package evaluation - -import ( - "github.com/ossf/scorecard/v4/finding" -) - -func falseFindings(findings []finding.Finding) []finding.Finding { - var ff []finding.Finding - for i := range findings { - f := &findings[i] - if f.Outcome == finding.OutcomeFalse { - ff = append(ff, *f) - } - } - return ff -} diff --git a/checks/evaluation/maintained.go b/checks/evaluation/maintained.go index fb974471f16..55aaf88412f 100644 --- a/checks/evaluation/maintained.go +++ b/checks/evaluation/maintained.go @@ -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]) @@ -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 + } + checker.LogFinding(dl, f, checker.DetailWarn) + default: + checker.LogFinding(dl, f, checker.DetailDebug) } } + 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") + } + 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 -} diff --git a/checks/evaluation/maintained_test.go b/checks/evaluation/maintained_test.go index d2ec527f940..61cb4e3f16f 100644 --- a/checks/evaluation/maintained_test.go +++ b/checks/evaluation/maintained_test.go @@ -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, @@ -77,7 +79,8 @@ func TestMaintained(t *testing.T) { }, }, result: scut.TestReturn{ - Score: 0, + Score: 0, + NumberOfWarn: 2, }, }, {