Skip to content

Commit 1c18a33

Browse files
committed
Revert #471 empty check
Signed-off-by: Jeff Mendoza <[email protected]>
1 parent 5bc0d49 commit 1c18a33

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

pkg/enforce/enforce.go

-31
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package enforce
1919
import (
2020
"context"
2121
"fmt"
22-
"net/http"
2322
"sync"
2423
"time"
2524

@@ -49,7 +48,6 @@ var getAppInstallationRepos func(context.Context, *github.Client) ([]*github.Rep
4948
var runPolicies func(context.Context, *github.Client, string, string, bool, string) (EnforceRepoResults, error)
5049
var deleteInstallation func(context.Context, *github.Client, int64) (*github.Response, error)
5150
var listInstallations func(context.Context, *github.Client) ([]*github.Installation, error)
52-
var isRepositoryEmpty func(context.Context, *github.Client, string, string, string) (bool, error)
5351

5452
func init() {
5553
policiesGetPolicies = policies.GetPolicies
@@ -61,7 +59,6 @@ func init() {
6159
runPolicies = runPoliciesReal
6260
deleteInstallation = deleteInstallationReal
6361
listInstallations = listInstallationsReal
64-
isRepositoryEmpty = isRepositoryEmptyReal
6562
}
6663

6764
// EnforceAll iterates through all available installations and repos Allstar
@@ -321,25 +318,6 @@ func EnforceJob(ctx context.Context, ghc *ghclients.GHClients, d time.Duration,
321318
}
322319
}
323320

324-
// returns true if the repository has content and false if it's empty
325-
func isRepositoryEmptyReal(ctx context.Context, c *github.Client, owner, repo, policy string) (bool, error) {
326-
opts := github.RepositoryContentGetOptions{}
327-
file, dirs, resp, err := c.Repositories.GetContents(ctx, owner, repo, "", &opts)
328-
if err != nil && resp.StatusCode != http.StatusNotFound {
329-
return false, err
330-
}
331-
if file == nil && len(dirs) == 0 {
332-
log.Info().
333-
Str("org", owner).
334-
Str("repo", repo).
335-
Str("area", policy).
336-
Msg("Repository is empty, skipping")
337-
return true, nil
338-
}
339-
340-
return false, nil
341-
}
342-
343321
// runPoliciesReal enforces policies on the provided repo. It is meant to be called
344322
// from either jobs, webhooks, or delayed checks. TODO: implement concurrency
345323
// check to only run a single instance per repo at a time.
@@ -373,15 +351,6 @@ func runPoliciesReal(ctx context.Context, c *github.Client, owner, repo string,
373351
continue
374352
}
375353

376-
isEmpty, err := isRepositoryEmpty(ctx, c, owner, repo, p.Name())
377-
if err != nil {
378-
return nil, err
379-
}
380-
381-
if isEmpty {
382-
continue
383-
}
384-
385354
r, err := p.Check(ctx, c, owner, repo)
386355
if err != nil {
387356
return nil, err

pkg/enforce/enforce_test.go

-39
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,6 @@ func (m MockGhClients) Get(i int64) (*github.Client, error) {
9191

9292
func (m MockGhClients) LogCacheSize() {}
9393

94-
func TestSkipEmptyRepositories(t *testing.T) {
95-
policiesGetPolicies = func() []policydef.Policy {
96-
return []policydef.Policy{
97-
pol{},
98-
}
99-
}
100-
101-
isRepositoryEmpty = func(ctx context.Context, c *github.Client, s1, s2, s3 string) (bool, error) {
102-
return true, nil
103-
}
104-
105-
repo := "fake-repo"
106-
107-
tests := []struct {
108-
Desc string
109-
}{
110-
{
111-
Desc: "test skip a single empty repository",
112-
},
113-
}
114-
115-
for _, test := range tests {
116-
t.Run(test.Desc, func(t *testing.T) {
117-
enforceResults, err := runPoliciesReal(context.Background(), nil, "", repo, true, "")
118-
119-
if err != nil {
120-
t.Fatalf("Unexpected error: %v", err)
121-
}
122-
123-
if len(enforceResults) != 0 {
124-
t.Errorf("expected no policy results, got %+v\n", enforceResults)
125-
}
126-
})
127-
}
128-
}
129-
13094
func TestRunPolicies(t *testing.T) {
13195
policiesGetPolicies = func() []policydef.Policy {
13296
return []policydef.Policy{
@@ -143,9 +107,6 @@ func TestRunPolicies(t *testing.T) {
143107
closeCalled = true
144108
return nil
145109
}
146-
isRepositoryEmpty = func(ctx context.Context, c *github.Client, s1, s2, s3 string) (bool, error) {
147-
return false, nil
148-
}
149110
repo := "fake-repo"
150111
tests := []struct {
151112
Name string

0 commit comments

Comments
 (0)