@@ -678,7 +678,11 @@ func (s *Source) addReposByApp(ctx context.Context, apiClient *github.Client) er
678678
679679func (s * Source ) addAllVisibleOrgs (ctx context.Context , apiClient * github.Client ) {
680680 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.
681684 orgOpts := & github.OrganizationsListOptions {
685+ Since : 0 ,
682686 ListOptions : github.ListOptions {
683687 PerPage : 100 ,
684688 },
@@ -695,7 +699,13 @@ func (s *Source) addAllVisibleOrgs(ctx context.Context, apiClient *github.Client
695699 log .WithError (err ).Errorf ("Could not list all organizations" )
696700 return
697701 }
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+
699709 for _ , org := range orgs {
700710 var name string
701711 if org .Name != nil {
@@ -705,13 +715,9 @@ func (s *Source) addAllVisibleOrgs(ctx context.Context, apiClient *github.Client
705715 } else {
706716 continue
707717 }
708- s .log .Debug ("adding organization for repository enumeration: " , name )
718+ s .log .Debugf ("adding organization %d for repository enumeration: %s" , org . ID , name )
709719 common .AddStringSliceItem (name , & s .orgs )
710720 }
711- if resp .NextPage == 0 {
712- break
713- }
714- orgOpts .Page = resp .NextPage
715721 }
716722}
717723
0 commit comments