@@ -235,11 +235,10 @@ func processRepository(ctx context.Context, client *api.RESTClient, graphQlClien
235235 // Continue processing
236236 }
237237
238- // Get open PRs for the repository
239- var pulls github.Pulls
240-
241- if err := client .Get (repo .PullsEndpoint (), & pulls ); err != nil {
242- return err
238+ // Fetch all open pull requests for the repository
239+ pulls , err := fetchOpenPullRequests (ctx , client , repo )
240+ if err != nil {
241+ return fmt .Errorf ("failed to fetch open pull requests: %w" , err )
243242 }
244243
245244 // Check for cancellation again
@@ -253,9 +252,7 @@ func processRepository(ctx context.Context, client *api.RESTClient, graphQlClien
253252 // Filter PRs based on criteria
254253 var matchedPRs github.Pulls
255254 for _ , pull := range pulls {
256- // Temporary workaround because passing structures is useless in this
257- // context.
258- // Eventually the []Labels should have better support.
255+ // Extract labels
259256 labels := []string {}
260257 for _ , label := range pull .Labels {
261258 labels = append (labels , label .Name )
@@ -290,10 +287,51 @@ func processRepository(ctx context.Context, client *api.RESTClient, graphQlClien
290287 Logger .Debug ("Matched PRs" , "repo" , repo , "count" , len (matchedPRs ))
291288
292289 // Combine the PRs
293- err : = CombinePRs (ctx , graphQlClient , client , repo , matchedPRs )
290+ err = CombinePRs (ctx , graphQlClient , client , repo , matchedPRs )
294291 if err != nil {
295292 return fmt .Errorf ("failed to combine PRs: %w" , err )
296293 }
297294
295+ Logger .Debug ("Combined PRs" , "count" , len (matchedPRs ), "owner" , repo .Owner , "repo" , repo .Repo )
296+
298297 return nil
299298}
299+
300+ // fetchOpenPullRequests fetches all open pull requests for a repository, handling pagination
301+ func fetchOpenPullRequests (ctx context.Context , client * api.RESTClient , repo github.Repo ) (github.Pulls , error ) {
302+ var allPulls github.Pulls
303+ page := 1
304+
305+ for {
306+ // Check for cancellation
307+ select {
308+ case <- ctx .Done ():
309+ return nil , ctx .Err ()
310+ default :
311+ // Continue processing
312+ }
313+
314+ var pulls github.Pulls
315+ endpoint := fmt .Sprintf ("%s?state=open&page=%d&per_page=100" , repo .PullsEndpoint (), page )
316+ if err := client .Get (endpoint , & pulls ); err != nil {
317+ return nil , fmt .Errorf ("failed to fetch pull requests from page %d: %w" , page , err )
318+ }
319+
320+ // If the current page is empty, we've reached the end
321+ if len (pulls ) == 0 {
322+ break
323+ }
324+
325+ // Append fetched pulls to the result
326+ allPulls = append (allPulls , pulls ... )
327+
328+ // If fewer than 100 PRs are returned, we've reached the last page
329+ if len (pulls ) < 100 {
330+ break
331+ }
332+
333+ page ++
334+ }
335+
336+ return allPulls , nil
337+ }
0 commit comments