Skip to content

Commit c368d8a

Browse files
⚠️ Rename top level package to scorecard and reduce name duplication (#4227)
* move files to scorecard package Signed-off-by: Spencer Schrock <[email protected]> * remove repetition from ScorecardResult Signed-off-by: Spencer Schrock <[email protected]> * update comments Signed-off-by: Spencer Schrock <[email protected]> * remove RunScorecard function Signed-off-by: Spencer Schrock <[email protected]> * add docstrings Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]>
1 parent a9ab4a9 commit c368d8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+239
-245
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# binary.
22
scorecard
3+
!pkg/scorecard
34
attestor/scorecard-attestor
45
scorecard.docker
56
scorecard.releaser

attestor/command/check.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/ossf/scorecard/v5/attestor/policy"
2323
"github.com/ossf/scorecard/v5/checker"
2424
sclog "github.com/ossf/scorecard/v5/log"
25-
"github.com/ossf/scorecard/v5/pkg"
25+
"github.com/ossf/scorecard/v5/pkg/scorecard"
2626
)
2727

2828
type EmptyParameterError struct {
@@ -91,16 +91,16 @@ func RunCheckWithParams(repoURL, commitSHA, policyPath string) (policy.PolicyRes
9191
}
9292
}
9393

94-
repoResult, err := pkg.Run(ctx, repo,
95-
pkg.WithCommitSHA(commitSHA),
96-
pkg.WithChecks(enabledChecks),
97-
pkg.WithRepoClient(repoClient),
98-
pkg.WithOSSFuzzClient(ossFuzzRepoClient),
99-
pkg.WithOpenSSFBestPraticesClient(ciiClient),
100-
pkg.WithVulnerabilitiesClient(vulnsClient),
94+
repoResult, err := scorecard.Run(ctx, repo,
95+
scorecard.WithCommitSHA(commitSHA),
96+
scorecard.WithChecks(enabledChecks),
97+
scorecard.WithRepoClient(repoClient),
98+
scorecard.WithOSSFuzzClient(ossFuzzRepoClient),
99+
scorecard.WithOpenSSFBestPraticesClient(ciiClient),
100+
scorecard.WithVulnerabilitiesClient(vulnsClient),
101101
)
102102
if err != nil {
103-
return policy.Fail, fmt.Errorf("RunScorecard: %w", err)
103+
return policy.Fail, fmt.Errorf("scorecard.Run: %w", err)
104104
}
105105

106106
result, err := attestationPolicy.EvaluateResults(&repoResult.RawResults)

cmd/internal/scdiff/app/compare.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
"github.com/ossf/scorecard/v5/cmd/internal/scdiff/app/compare"
2929
"github.com/ossf/scorecard/v5/cmd/internal/scdiff/app/format"
30-
"github.com/ossf/scorecard/v5/pkg"
30+
"github.com/ossf/scorecard/v5/pkg/scorecard"
3131
)
3232

3333
//nolint:gochecknoinits // common for cobra apps
@@ -93,14 +93,14 @@ func compareReaders(x, y io.Reader, output io.Writer) error {
9393
return nil
9494
}
9595

96-
func loadResults(x, y *bufio.Scanner) (pkg.ScorecardResult, pkg.ScorecardResult, error) {
97-
xResult, _, err := pkg.ExperimentalFromJSON2(strings.NewReader(x.Text()))
96+
func loadResults(x, y *bufio.Scanner) (scorecard.Result, scorecard.Result, error) {
97+
xResult, _, err := scorecard.ExperimentalFromJSON2(strings.NewReader(x.Text()))
9898
if err != nil {
99-
return pkg.ScorecardResult{}, pkg.ScorecardResult{}, fmt.Errorf("parsing first result: %w", err)
99+
return scorecard.Result{}, scorecard.Result{}, fmt.Errorf("parsing first result: %w", err)
100100
}
101-
yResult, _, err := pkg.ExperimentalFromJSON2(strings.NewReader(y.Text()))
101+
yResult, _, err := scorecard.ExperimentalFromJSON2(strings.NewReader(y.Text()))
102102
if err != nil {
103-
return pkg.ScorecardResult{}, pkg.ScorecardResult{}, fmt.Errorf("parsing second result: %w", err)
103+
return scorecard.Result{}, scorecard.Result{}, fmt.Errorf("parsing second result: %w", err)
104104
}
105105
format.Normalize(&xResult)
106106
format.Normalize(&yResult)

cmd/internal/scdiff/app/compare/compare.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
package compare
1616

17-
import "github.com/ossf/scorecard/v5/pkg"
17+
import "github.com/ossf/scorecard/v5/pkg/scorecard"
1818

1919
// results should be normalized before comparison.
20-
func Results(r1, r2 *pkg.ScorecardResult) bool {
20+
func Results(r1, r2 *scorecard.Result) bool {
2121
if r1 == nil && r2 == nil {
2222
return true
2323
}
@@ -40,7 +40,7 @@ func Results(r1, r2 *pkg.ScorecardResult) bool {
4040
return true
4141
}
4242

43-
func compareChecks(r1, r2 *pkg.ScorecardResult) bool {
43+
func compareChecks(r1, r2 *scorecard.Result) bool {
4444
if len(r1.Checks) != len(r2.Checks) {
4545
return false
4646
}

cmd/internal/scdiff/app/compare/compare_test.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import (
1818
"testing"
1919

2020
"github.com/ossf/scorecard/v5/checker"
21-
"github.com/ossf/scorecard/v5/pkg"
21+
"github.com/ossf/scorecard/v5/pkg/scorecard"
2222
)
2323

2424
func TestResults(t *testing.T) {
2525
t.Parallel()
2626
//nolint:govet // field alignment
2727
tests := []struct {
2828
name string
29-
a, b *pkg.ScorecardResult
29+
a, b *scorecard.Result
3030
wantEqual bool
3131
}{
3232
{
@@ -38,26 +38,26 @@ func TestResults(t *testing.T) {
3838
{
3939
name: "one nil",
4040
a: nil,
41-
b: &pkg.ScorecardResult{},
41+
b: &scorecard.Result{},
4242
wantEqual: false,
4343
},
4444
{
4545
name: "different repo name",
46-
a: &pkg.ScorecardResult{
47-
Repo: pkg.RepoInfo{
46+
a: &scorecard.Result{
47+
Repo: scorecard.RepoInfo{
4848
Name: "a",
4949
},
5050
},
51-
b: &pkg.ScorecardResult{
52-
Repo: pkg.RepoInfo{
51+
b: &scorecard.Result{
52+
Repo: scorecard.RepoInfo{
5353
Name: "b",
5454
},
5555
},
5656
wantEqual: false,
5757
},
5858
{
5959
name: "unequal amount of checks",
60-
a: &pkg.ScorecardResult{
60+
a: &scorecard.Result{
6161
Checks: []checker.CheckResult{
6262
{
6363
Name: "a1",
@@ -67,7 +67,7 @@ func TestResults(t *testing.T) {
6767
},
6868
},
6969
},
70-
b: &pkg.ScorecardResult{
70+
b: &scorecard.Result{
7171
Checks: []checker.CheckResult{
7272
{
7373
Name: "b",
@@ -78,14 +78,14 @@ func TestResults(t *testing.T) {
7878
},
7979
{
8080
name: "different check name",
81-
a: &pkg.ScorecardResult{
81+
a: &scorecard.Result{
8282
Checks: []checker.CheckResult{
8383
{
8484
Name: "a",
8585
},
8686
},
8787
},
88-
b: &pkg.ScorecardResult{
88+
b: &scorecard.Result{
8989
Checks: []checker.CheckResult{
9090
{
9191
Name: "b",
@@ -96,14 +96,14 @@ func TestResults(t *testing.T) {
9696
},
9797
{
9898
name: "different check score",
99-
a: &pkg.ScorecardResult{
99+
a: &scorecard.Result{
100100
Checks: []checker.CheckResult{
101101
{
102102
Score: 1,
103103
},
104104
},
105105
},
106-
b: &pkg.ScorecardResult{
106+
b: &scorecard.Result{
107107
Checks: []checker.CheckResult{
108108
{
109109
Score: 2,
@@ -114,14 +114,14 @@ func TestResults(t *testing.T) {
114114
},
115115
{
116116
name: "different check reason",
117-
a: &pkg.ScorecardResult{
117+
a: &scorecard.Result{
118118
Checks: []checker.CheckResult{
119119
{
120120
Reason: "a",
121121
},
122122
},
123123
},
124-
b: &pkg.ScorecardResult{
124+
b: &scorecard.Result{
125125
Checks: []checker.CheckResult{
126126
{
127127
Reason: "b",
@@ -132,14 +132,14 @@ func TestResults(t *testing.T) {
132132
},
133133
{
134134
name: "unequal number of details",
135-
a: &pkg.ScorecardResult{
135+
a: &scorecard.Result{
136136
Checks: []checker.CheckResult{
137137
{
138138
Details: []checker.CheckDetail{},
139139
},
140140
},
141141
},
142-
b: &pkg.ScorecardResult{
142+
b: &scorecard.Result{
143143
Checks: []checker.CheckResult{
144144
{
145145
Details: []checker.CheckDetail{
@@ -154,7 +154,7 @@ func TestResults(t *testing.T) {
154154
},
155155
{
156156
name: "details have different levels",
157-
a: &pkg.ScorecardResult{
157+
a: &scorecard.Result{
158158
Checks: []checker.CheckResult{
159159
{
160160
Details: []checker.CheckDetail{
@@ -165,7 +165,7 @@ func TestResults(t *testing.T) {
165165
},
166166
},
167167
},
168-
b: &pkg.ScorecardResult{
168+
b: &scorecard.Result{
169169
Checks: []checker.CheckResult{
170170
{
171171
Details: []checker.CheckDetail{
@@ -180,8 +180,8 @@ func TestResults(t *testing.T) {
180180
},
181181
{
182182
name: "equal results",
183-
a: &pkg.ScorecardResult{
184-
Repo: pkg.RepoInfo{
183+
a: &scorecard.Result{
184+
Repo: scorecard.RepoInfo{
185185
Name: "foo",
186186
},
187187
Checks: []checker.CheckResult{
@@ -195,8 +195,8 @@ func TestResults(t *testing.T) {
195195
},
196196
},
197197
},
198-
b: &pkg.ScorecardResult{
199-
Repo: pkg.RepoInfo{
198+
b: &scorecard.Result{
199+
Repo: scorecard.RepoInfo{
200200
Name: "foo",
201201
},
202202
Checks: []checker.CheckResult{

cmd/internal/scdiff/app/format/format.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ import (
2121

2222
"github.com/ossf/scorecard/v5/docs/checks"
2323
"github.com/ossf/scorecard/v5/log"
24-
"github.com/ossf/scorecard/v5/pkg"
24+
"github.com/ossf/scorecard/v5/pkg/scorecard"
2525
)
2626

2727
const logLevel = log.DefaultLevel
2828

29-
func Normalize(r *pkg.ScorecardResult) {
29+
func Normalize(r *scorecard.Result) {
3030
if r == nil {
3131
return
3232
}
3333

3434
// these fields will change run-to-run, and aren't indicative of behavior changes.
3535
r.Repo.CommitSHA = ""
36-
r.Scorecard = pkg.ScorecardInfo{}
36+
r.Scorecard = scorecard.ScorecardInfo{}
3737
r.Date = time.Time{}
3838

3939
sort.Slice(r.Checks, func(i, j int) bool {
@@ -43,20 +43,20 @@ func Normalize(r *pkg.ScorecardResult) {
4343
for i := range r.Checks {
4444
check := &r.Checks[i]
4545
sort.Slice(check.Details, func(i, j int) bool {
46-
return pkg.DetailToString(&check.Details[i], logLevel) < pkg.DetailToString(&check.Details[j], logLevel)
46+
return scorecard.DetailToString(&check.Details[i], logLevel) < scorecard.DetailToString(&check.Details[j], logLevel)
4747
})
4848
}
4949
}
5050

5151
//nolint:wrapcheck
52-
func JSON(r *pkg.ScorecardResult, w io.Writer) error {
52+
func JSON(r *scorecard.Result, w io.Writer) error {
5353
const details = true
5454
docs, err := checks.Read()
5555
if err != nil {
5656
return err
5757
}
5858
Normalize(r)
59-
o := &pkg.AsJSON2ResultOption{
59+
o := &scorecard.AsJSON2ResultOption{
6060
Details: details,
6161
LogLevel: logLevel,
6262
}

0 commit comments

Comments
 (0)