Skip to content

Commit 7144232

Browse files
authored
Chunk orgs the same when authenticated as unauthenticated (#501)
Also debug log the amount of forks we find in addReposByOrg.
1 parent 1bd5e9d commit 7144232

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ require (
9393
github.com/mitchellh/go-homedir v1.1.0 // indirect
9494
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
9595
github.com/modern-go/reflect2 v1.0.1 // indirect
96+
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27 // indirect
97+
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69 // indirect
9698
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7 // indirect
9799
github.com/xanzy/ssh-agent v0.3.0 // indirect
98100
github.com/yusufpapurcu/wmi v1.2.2 // indirect

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
387387
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
388388
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
389389
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
390+
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27 h1:uAI3rnOT1OSSY4PUtI/M1orb3q0ewkovwd3wr8xSno4=
391+
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27/go.mod h1:6eu9CfGt5kfrMVgeu9MfB9PRUnpc47I+udLswiTszI8=
392+
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69 h1:1KtusfE10/BxzK4Vks+ULP7S63TicyRu6cq86vCRWX8=
393+
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69/go.mod h1:xUDtqIPhzzkB+XSl0pW8qQKXzzR+SU6xcZToxwKi5zA=
390394
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
391395
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
392396
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@@ -412,6 +416,7 @@ github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
412416
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
413417
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
414418
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
419+
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
415420
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
416421
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
417422
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
@@ -568,6 +573,7 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
568573
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
569574
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
570575
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
576+
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
571577
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
572578
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
573579
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=

pkg/sources/github/github.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk) err
198198
if len(s.orgs) > 0 {
199199
specificScope = true
200200
for _, org := range s.orgs {
201-
if !strings.HasSuffix(org, ".git") {
202-
s.addReposByOrg(ctx, apiClient, org)
203-
s.addReposByUser(ctx, apiClient, org)
201+
errOrg := s.addReposByOrg(ctx, apiClient, org)
202+
errUser := s.addReposByUser(ctx, apiClient, org)
203+
if errOrg != nil && errUser != nil {
204+
log.WithError(errOrg).Error("error fetching repos for org or user: ", org)
204205
}
205206
}
206207
}
@@ -412,6 +413,7 @@ func (s *Source) addReposByOrg(ctx context.Context, apiClient *github.Client, or
412413
PerPage: 100,
413414
},
414415
}
416+
var numRepos, numForks int
415417
for {
416418
someRepos, res, err := apiClient.Repositories.ListByOrg(ctx, org, opts)
417419
if err == nil {
@@ -427,8 +429,12 @@ func (s *Source) addReposByOrg(ctx context.Context, apiClient *github.Client, or
427429
break
428430
}
429431
for _, r := range someRepos {
430-
if r.GetFork() && !s.conn.IncludeForks {
431-
continue
432+
numRepos++
433+
if r.GetFork() {
434+
numForks++
435+
if !s.conn.IncludeForks {
436+
continue
437+
}
432438
}
433439
common.AddStringSliceItem(r.GetCloneURL(), &s.repos)
434440
}
@@ -437,6 +443,7 @@ func (s *Source) addReposByOrg(ctx context.Context, apiClient *github.Client, or
437443
}
438444
opts.Page = res.NextPage
439445
}
446+
log.WithField("org", org).Debugf("Found %d repos (%d forks)", numRepos, numForks)
440447
return nil
441448
}
442449

0 commit comments

Comments
 (0)