@@ -315,13 +315,15 @@ func (g *mqlGithubOrganization) repositories() ([]any, error) {
315315 }
316316
317317 repoCount := g .TotalPrivateRepos .Data + g .TotalPublicRepos .Data
318- workerPool := workerpool.New [[]* github.Repository ](workers )
318+ expectedPages := int (repoCount )/ paginationPerPage + 1
319+ workerCount := int (repoCount )/ paginationPerPage + 1
320+ workerPool := workerpool.New [[]* github.Repository ](workerCount )
319321 workerPool .Start ()
320322 defer workerPool .Close ()
321323
322324 log .Debug ().
323- Int ("workers" , workers ).
324- Int64 ("total_repos " , repoCount ).
325+ Int ("workers" , workerCount ).
326+ Int64 ("total-repos " , repoCount ).
325327 Str ("organization" , g .Name .Data ).
326328 Msg ("list repositories" )
327329
@@ -332,6 +334,19 @@ func (g *mqlGithubOrganization) repositories() ([]any, error) {
332334 break
333335 }
334336
337+ // failsafe: when total count is correct but some repos aren't returned from ListByOrg
338+ // (e.g., due to permission issues), we stop after enough pages have been requested
339+ // plus the number of pending workers to account for concurrency
340+ if listOpts .Page > (int (workerPool .PendingRequests ()) + expectedPages ) {
341+ log .Warn ().
342+ Int ("found-repos" , reposLen ).
343+ Int64 ("total-repos" , repoCount ).
344+ Int ("page" , listOpts .Page ).
345+ Int ("per-page" , listOpts .PerPage ).
346+ Msg ("Failsafe triggered, no more repos are returned" )
347+ break
348+ }
349+
335350 // send requests to workers
336351 opts := listOpts
337352 workerPool .Submit (func () ([]* github.Repository , error ) {
0 commit comments