Skip to content

Commit fea6945

Browse files
committed
🌱 Add tagsHandler to githubrepo client
Signed-off-by: Adam Korczynski <[email protected]>
1 parent 4057678 commit fea6945

File tree

50 files changed

+1468
-376
lines changed

Some content is hidden

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

50 files changed

+1468
-376
lines changed

checker/raw_result.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
type RawResults struct {
3030
BinaryArtifactResults BinaryArtifactData
3131
BranchProtectionResults BranchProtectionsData
32+
TagProtectionResults TagProtectionsData
3233
CIIBestPracticesResults CIIBestPracticesData
3334
CITestResults CITestData
3435
CodeReviewResults CodeReviewData
@@ -332,7 +333,14 @@ type WebhooksData struct {
332333
// BranchProtectionsData contains the raw results
333334
// for the Branch-Protection check.
334335
type BranchProtectionsData struct {
335-
Branches []clients.BranchRef
336+
Branches []clients.RepoRef
337+
CodeownersFiles []string
338+
}
339+
340+
// TagProtectionsData contains the raw results
341+
// for the Tag-Protection check.
342+
type TagProtectionsData struct {
343+
Tags []clients.RepoRef
336344
CodeownersFiles []string
337345
}
338346

checks/branch_protection_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import (
2626
scut "github.com/ossf/scorecard/v5/utests"
2727
)
2828

29-
func getBranchName(branch *clients.BranchRef) string {
29+
func getBranchName(branch *clients.RepoRef) string {
3030
if branch == nil || branch.Name == nil {
3131
return ""
3232
}
3333
return *branch.Name
3434
}
3535

36-
func getBranch(branches []*clients.BranchRef, name string, isNonAdmin bool) *clients.BranchRef {
36+
func getBranch(branches []*clients.RepoRef, name string, isNonAdmin bool) *clients.RepoRef {
3737
for _, branch := range branches {
3838
branchName := getBranchName(branch)
3939
if branchName == name {
@@ -46,9 +46,9 @@ func getBranch(branches []*clients.BranchRef, name string, isNonAdmin bool) *cli
4646
return nil
4747
}
4848

49-
func scrubBranch(branch *clients.BranchRef) *clients.BranchRef {
49+
func scrubBranch(branch *clients.RepoRef) *clients.RepoRef {
5050
ret := branch
51-
ret.BranchProtectionRule = clients.BranchProtectionRule{}
51+
ret.ProtectionRule = clients.ProtectionRule{}
5252
return ret
5353
}
5454

@@ -67,7 +67,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
6767
tests := []struct {
6868
name string
6969
defaultBranch string
70-
branches []*clients.BranchRef
70+
branches []*clients.RepoRef
7171
releases []string
7272
repoFiles []string
7373
expected scut.TestReturn
@@ -83,10 +83,10 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
8383
NumberOfDebug: 0,
8484
},
8585
defaultBranch: main,
86-
branches: []*clients.BranchRef{
86+
branches: []*clients.RepoRef{
8787
{
8888
Protected: &trueVal,
89-
BranchProtectionRule: clients.BranchProtectionRule{
89+
ProtectionRule: clients.ProtectionRule{
9090
CheckRules: clients.StatusChecksRule{
9191
RequiresStatusChecks: &trueVal,
9292
UpToDateBeforeMerge: &trueVal,
@@ -106,7 +106,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
106106
},
107107
{
108108
Protected: &trueVal,
109-
BranchProtectionRule: clients.BranchProtectionRule{
109+
ProtectionRule: clients.ProtectionRule{
110110
CheckRules: clients.StatusChecksRule{
111111
RequiresStatusChecks: &trueVal,
112112
UpToDateBeforeMerge: &falseVal,
@@ -138,15 +138,15 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
138138
NumberOfDebug: 0,
139139
},
140140
defaultBranch: main,
141-
branches: []*clients.BranchRef{
141+
branches: []*clients.RepoRef{
142142
{
143143
Name: &rel1,
144144
Protected: &falseVal,
145145
},
146146
{
147147
Name: &main,
148148
Protected: &trueVal,
149-
BranchProtectionRule: clients.BranchProtectionRule{
149+
ProtectionRule: clients.ProtectionRule{
150150
CheckRules: clients.StatusChecksRule{
151151
RequiresStatusChecks: &trueVal,
152152
UpToDateBeforeMerge: &falseVal,
@@ -178,11 +178,11 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
178178
NumberOfDebug: 0,
179179
},
180180
defaultBranch: main,
181-
branches: []*clients.BranchRef{
181+
branches: []*clients.RepoRef{
182182
{
183183
Name: &main,
184184
Protected: &trueVal,
185-
BranchProtectionRule: clients.BranchProtectionRule{
185+
ProtectionRule: clients.ProtectionRule{
186186
CheckRules: clients.StatusChecksRule{
187187
RequiresStatusChecks: &trueVal,
188188
UpToDateBeforeMerge: &trueVal,
@@ -204,7 +204,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
204204
{
205205
Name: &rel1,
206206
Protected: &trueVal,
207-
BranchProtectionRule: clients.BranchProtectionRule{
207+
ProtectionRule: clients.ProtectionRule{
208208
CheckRules: clients.StatusChecksRule{
209209
RequiresStatusChecks: &trueVal,
210210
UpToDateBeforeMerge: &falseVal,
@@ -236,11 +236,11 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
236236
NumberOfDebug: 0,
237237
},
238238
defaultBranch: main,
239-
branches: []*clients.BranchRef{
239+
branches: []*clients.RepoRef{
240240
{
241241
Name: &main,
242242
Protected: &trueVal,
243-
BranchProtectionRule: clients.BranchProtectionRule{
243+
ProtectionRule: clients.ProtectionRule{
244244
CheckRules: clients.StatusChecksRule{
245245
RequiresStatusChecks: &trueVal,
246246
UpToDateBeforeMerge: &trueVal,
@@ -262,7 +262,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
262262
{
263263
Name: &rel1,
264264
Protected: &trueVal,
265-
BranchProtectionRule: clients.BranchProtectionRule{
265+
ProtectionRule: clients.ProtectionRule{
266266
CheckRules: clients.StatusChecksRule{
267267
RequiresStatusChecks: &trueVal,
268268
UpToDateBeforeMerge: &trueVal,
@@ -295,11 +295,11 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
295295
},
296296
defaultBranch: main,
297297
releases: []string{sha},
298-
branches: []*clients.BranchRef{
298+
branches: []*clients.RepoRef{
299299
{
300300
Name: &main,
301301
Protected: &trueVal,
302-
BranchProtectionRule: clients.BranchProtectionRule{
302+
ProtectionRule: clients.ProtectionRule{
303303
CheckRules: clients.StatusChecksRule{
304304
RequiresStatusChecks: &trueVal,
305305
UpToDateBeforeMerge: &falseVal,
@@ -334,11 +334,11 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
334334
},
335335
defaultBranch: main,
336336
releases: []string{""},
337-
branches: []*clients.BranchRef{
337+
branches: []*clients.RepoRef{
338338
{
339339
Name: &main,
340340
Protected: &trueVal,
341-
BranchProtectionRule: clients.BranchProtectionRule{
341+
ProtectionRule: clients.ProtectionRule{
342342
CheckRules: clients.StatusChecksRule{
343343
RequiresStatusChecks: &trueVal,
344344
UpToDateBeforeMerge: &falseVal,
@@ -371,11 +371,11 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
371371
defaultBranch: main,
372372
// branches: []*string{&rel1, &main},
373373
releases: []string{rel1},
374-
branches: []*clients.BranchRef{
374+
branches: []*clients.RepoRef{
375375
{
376376
Name: &main,
377377
Protected: &trueVal,
378-
BranchProtectionRule: clients.BranchProtectionRule{
378+
ProtectionRule: clients.ProtectionRule{
379379
CheckRules: clients.StatusChecksRule{
380380
RequiresStatusChecks: &trueVal,
381381
UpToDateBeforeMerge: &trueVal,
@@ -386,7 +386,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
386386
{
387387
Name: &rel1,
388388
Protected: &trueVal,
389-
BranchProtectionRule: clients.BranchProtectionRule{
389+
ProtectionRule: clients.ProtectionRule{
390390
CheckRules: clients.StatusChecksRule{
391391
RequiresStatusChecks: &trueVal,
392392
UpToDateBeforeMerge: &trueVal,
@@ -405,7 +405,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
405405
ctrl := gomock.NewController(t)
406406
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
407407
mockRepoClient.EXPECT().GetDefaultBranch().
408-
DoAndReturn(func() (*clients.BranchRef, error) {
408+
DoAndReturn(func() (*clients.RepoRef, error) {
409409
defaultBranch := getBranch(tt.branches, tt.defaultBranch, tt.nonadmin)
410410
return defaultBranch, nil
411411
}).AnyTimes()
@@ -420,7 +420,7 @@ func TestReleaseAndDevBranchProtected(t *testing.T) {
420420
return ret, nil
421421
}).AnyTimes()
422422
mockRepoClient.EXPECT().GetBranch(gomock.Any()).
423-
DoAndReturn(func(b string) (*clients.BranchRef, error) {
423+
DoAndReturn(func(b string) (*clients.RepoRef, error) {
424424
return getBranch(tt.branches, b, tt.nonadmin), nil
425425
}).AnyTimes()
426426
mockRepoClient.EXPECT().ListFiles(gomock.Any()).AnyTimes().Return(tt.repoFiles, nil)

checks/permissions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func TestGithubTokenPermissions(t *testing.T) {
434434

435435
main := "main"
436436
mockRepo.EXPECT().URI().Return("github.com/ossf/scorecard").AnyTimes()
437-
mockRepo.EXPECT().GetDefaultBranch().Return(&clients.BranchRef{Name: &main}, nil).AnyTimes()
437+
mockRepo.EXPECT().GetDefaultBranch().Return(&clients.RepoRef{Name: &main}, nil).AnyTimes()
438438
mockRepo.EXPECT().ListFiles(gomock.Any()).DoAndReturn(func(predicate func(string) (bool, error)) ([]string, error) {
439439
files := []string{}
440440
for _, fn := range tt.filenames {

checks/raw/branch_protection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ var commit = regexp.MustCompile("^[a-f0-9]{40}$")
3131

3232
type branchSet struct {
3333
exists map[string]bool
34-
set []clients.BranchRef
34+
set []clients.RepoRef
3535
}
3636

37-
func (set *branchSet) add(branch *clients.BranchRef) bool {
37+
func (set *branchSet) add(branch *clients.RepoRef) bool {
3838
if branch != nil &&
3939
branch.Name != nil &&
4040
*branch.Name != "" &&

checks/raw/branch_protection_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ var (
3737
type branchArg struct {
3838
err error
3939
name string
40-
branchRef *clients.BranchRef
40+
branchRef *clients.RepoRef
4141
defaultBranch bool
4242
}
4343

4444
type branchesArg []branchArg
4545

46-
func (ba branchesArg) getDefaultBranch() (*clients.BranchRef, error) {
46+
func (ba branchesArg) getDefaultBranch() (*clients.RepoRef, error) {
4747
for _, branch := range ba {
4848
if branch.defaultBranch {
4949
return branch.branchRef, branch.err
@@ -52,7 +52,7 @@ func (ba branchesArg) getDefaultBranch() (*clients.BranchRef, error) {
5252
return nil, nil
5353
}
5454

55-
func (ba branchesArg) getBranch(b string) (*clients.BranchRef, error) {
55+
func (ba branchesArg) getBranch(b string) (*clients.RepoRef, error) {
5656
for _, branch := range ba {
5757
if branch.name == b {
5858
return branch.branchRef, branch.err
@@ -104,13 +104,13 @@ func TestBranchProtection(t *testing.T) {
104104
{
105105
name: defaultBranchName,
106106
defaultBranch: true,
107-
branchRef: &clients.BranchRef{
107+
branchRef: &clients.RepoRef{
108108
Name: &defaultBranchName,
109109
},
110110
},
111111
},
112112
want: checker.BranchProtectionsData{
113-
Branches: []clients.BranchRef{
113+
Branches: []clients.RepoRef{
114114
{
115115
Name: &defaultBranchName,
116116
},
@@ -180,13 +180,13 @@ func TestBranchProtection(t *testing.T) {
180180
branches: branchesArg{
181181
{
182182
name: releaseBranchName,
183-
branchRef: &clients.BranchRef{
183+
branchRef: &clients.RepoRef{
184184
Name: &releaseBranchName,
185185
},
186186
},
187187
},
188188
want: checker.BranchProtectionsData{
189-
Branches: []clients.BranchRef{
189+
Branches: []clients.RepoRef{
190190
{
191191
Name: &releaseBranchName,
192192
},
@@ -204,13 +204,13 @@ func TestBranchProtection(t *testing.T) {
204204
branches: branchesArg{
205205
{
206206
name: mainBranchName,
207-
branchRef: &clients.BranchRef{
207+
branchRef: &clients.RepoRef{
208208
Name: &mainBranchName,
209209
},
210210
},
211211
},
212212
want: checker.BranchProtectionsData{
213-
Branches: []clients.BranchRef{
213+
Branches: []clients.RepoRef{
214214
{
215215
Name: &mainBranchName,
216216
},
@@ -229,19 +229,19 @@ func TestBranchProtection(t *testing.T) {
229229
{
230230
name: defaultBranchName,
231231
defaultBranch: true,
232-
branchRef: &clients.BranchRef{
232+
branchRef: &clients.RepoRef{
233233
Name: &defaultBranchName,
234234
},
235235
},
236236
{
237237
name: releaseBranchName,
238-
branchRef: &clients.BranchRef{
238+
branchRef: &clients.RepoRef{
239239
Name: &releaseBranchName,
240240
},
241241
},
242242
},
243243
want: checker.BranchProtectionsData{
244-
Branches: []clients.BranchRef{
244+
Branches: []clients.RepoRef{
245245
{
246246
Name: &defaultBranchName,
247247
},
@@ -260,11 +260,11 @@ func TestBranchProtection(t *testing.T) {
260260
ctrl := gomock.NewController(t)
261261
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
262262
mockRepoClient.EXPECT().GetDefaultBranch().
263-
AnyTimes().DoAndReturn(func() (*clients.BranchRef, error) {
263+
AnyTimes().DoAndReturn(func() (*clients.RepoRef, error) {
264264
return tt.branches.getDefaultBranch()
265265
})
266266
mockRepoClient.EXPECT().GetBranch(gomock.Any()).AnyTimes().
267-
DoAndReturn(func(branch string) (*clients.BranchRef, error) {
267+
DoAndReturn(func(branch string) (*clients.RepoRef, error) {
268268
return tt.branches.getBranch(branch)
269269
})
270270
mockRepoClient.EXPECT().ListReleases().AnyTimes().

0 commit comments

Comments
 (0)