Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 sort organizations in Contributors detail string #4436

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, ", "),
})
}
Loading