@@ -678,7 +678,11 @@ func (s *Source) addReposByApp(ctx context.Context, apiClient *github.Client) er
678
678
679
679
func (s * Source ) addAllVisibleOrgs (ctx context.Context , apiClient * github.Client ) {
680
680
s .log .Debug ("enumerating all visibile organizations on GHE" )
681
+ // Enumeration on this endpoint does not use pages. it uses a since ID.
682
+ // The endpoint will return organizations with an ID greater than the given since ID.
683
+ // Empty org response is our cue to break the enumeration loop.
681
684
orgOpts := & github.OrganizationsListOptions {
685
+ Since : 0 ,
682
686
ListOptions : github.ListOptions {
683
687
PerPage : 100 ,
684
688
},
@@ -695,7 +699,13 @@ func (s *Source) addAllVisibleOrgs(ctx context.Context, apiClient *github.Client
695
699
log .WithError (err ).Errorf ("Could not list all organizations" )
696
700
return
697
701
}
698
- s .log .Debugf ("listed organization page %d/%d" , orgOpts .Page , resp .LastPage )
702
+ if len (orgs ) == 0 {
703
+ break
704
+ }
705
+ lastOrgID := * orgs [len (orgs )- 1 ].ID
706
+ s .log .Debugf ("listed organization IDs %d through %d" , orgOpts .Since , lastOrgID )
707
+ orgOpts .Since = lastOrgID
708
+
699
709
for _ , org := range orgs {
700
710
var name string
701
711
if org .Name != nil {
@@ -705,13 +715,9 @@ func (s *Source) addAllVisibleOrgs(ctx context.Context, apiClient *github.Client
705
715
} else {
706
716
continue
707
717
}
708
- s .log .Debug ("adding organization for repository enumeration: " , name )
718
+ s .log .Debugf ("adding organization %d for repository enumeration: %s" , org . ID , name )
709
719
common .AddStringSliceItem (name , & s .orgs )
710
720
}
711
- if resp .NextPage == 0 {
712
- break
713
- }
714
- orgOpts .Page = resp .NextPage
715
721
}
716
722
}
717
723
0 commit comments