Skip to content

Commit

Permalink
Merge branch 'main' into azure-devops-contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerschrock authored Dec 10, 2024
2 parents 1f7e0d2 + 687b739 commit d94ab0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
23 changes: 18 additions & 5 deletions checks/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package checks

import (
"errors"
"strings"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -30,10 +31,11 @@ import (
func TestContributors(t *testing.T) {
t.Parallel()
tests := []struct {
err error
name string
contrib []clients.User
expected checker.CheckResult
err error
name string
contrib []clients.User
expectedDetail string
expected checker.CheckResult
}{
{
err: nil,
Expand Down Expand Up @@ -133,6 +135,7 @@ func TestContributors(t *testing.T) {
expected: checker.CheckResult{
Score: 10,
},
expectedDetail: "found contributions from: company1, company2, company3, company4, company5, org1, org2",
},
{
err: nil,
Expand Down Expand Up @@ -182,7 +185,17 @@ func TestContributors(t *testing.T) {
if res.Score != tt.expected.Score {
t.Errorf("Expected score %d, got %d for %v", tt.expected.Score, res.Score, tt.name)
}
ctrl.Finish()
// make sure the output stays relatively stable
if tt.expectedDetail != "" {
details := req.Dlogger.Flush()
if len(details) != 1 {
t.Errorf("expected one check detail, got %d", len(details))
}
detail := details[0].Msg.Text
if !strings.Contains(detail, tt.expectedDetail) {
t.Errorf("expected %q but didn't find it: %q", tt.expectedDetail, detail)
}
}
})
}
}
10 changes: 7 additions & 3 deletions checks/evaluation/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package evaluation

import (
"fmt"
"slices"
"strings"

"github.com/ossf/scorecard/v5/checker"
Expand Down Expand Up @@ -69,14 +70,17 @@ func getNumberOfTrue(findings []finding.Finding) int {
}

func logFindings(findings []finding.Finding, dl checker.DetailLogger) {
var sb strings.Builder
var orgs []string
const suffix = " contributor org/company found"
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomeTrue {
sb.WriteString(fmt.Sprintf("%s, ", f.Message))
org := strings.TrimSuffix(f.Message, suffix)
orgs = append(orgs, org)
}
}
slices.Sort(orgs)
dl.Info(&checker.LogMessage{
Text: sb.String(),
Text: "found contributions from: " + strings.Join(orgs, ", "),
})
}

0 comments on commit d94ab0f

Please sign in to comment.