Fix pagination bug and type safety issues in GitHub runners API #7032
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the critical issues identified in PR #7027 reviews, particularly @ZainRizvi's report of incorrect runner statistics and type safety concerns.
Issues Fixed
Pagination Bug (Zain's Review)
The API was only fetching the first 100 runners from GitHub's API but returning the total count from the API response, leading to inconsistent statistics like "3189 total runners, 96 online, 46 busy" where the math clearly doesn't add up.
Root Cause: The original implementation used a single API call with
per_page: 100
, but GitHub's runners API paginates results. For organizations with 3000+ runners, this meant:total_count
: 3189 (from GitHub API)runners.length
: 100 (only first page fetched)onlineRunners
: 96 (calculated from incomplete data)busyRunners
: 46 (calculated from incomplete data)Solution: Implemented proper pagination with
fetchAllRunners()
function that:total_count
Type Safety Issues (Copilot Review)
The code used
any
types for GitHub API responses, defeating TypeScript's type safety benefits.Solution:
GitHubRunnerLabel
)Technical Changes
torchci/pages/api/runners/[org].ts
: Added pagination logic and proper TypeScript interfacestorchci/test/runners-api.test.ts
: Added comprehensive test coverageBehavior Changes
Before: API returned mathematically inconsistent numbers
After: API returns accurate, consistent numbers
The fix ensures that for any organization, the runner statistics will be mathematically consistent and calculated from the complete dataset.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.