feat(api-usage): adds rate limit insights and usage tracking#58
Merged
wgordon17 merged 14 commits intogordon-code:mainfrom Apr 8, 2026
Merged
Conversation
Replaces 15 manual trackApiCall() calls and 8 updateResetAt() calls
with a single hook.wrap("request", ...) on the Octokit client. New API
calls are tracked automatically with zero manual instrumentation.
- Adds ApiRequestInfo interface and onApiRequest() callback to github.ts
- Adds hook.wrap("request", ...) to createGitHubClient() for automatic
tracking, rate limit header extraction, and error path coverage
- Adds deriveSource() URL pattern matching in api-usage.ts to auto-detect
REST source labels from URL patterns
- Passes apiSource metadata on GraphQL calls for display labels
- Removes all trackApiCall/updateResetAt calls from api.ts, poll.ts,
and DashboardPage.tsx
- Removes fromCache from fetchRateLimitDetails return type
- Adds "graphql" and "rest" fallback source types for untagged calls
@octokit/graphql treats unknown top-level options as GraphQL variables, burying apiSource in the request body where the hook cannot read it. Passes apiSource through the `request` option instead, which is in NON_VARIABLE_OPTIONS and preserved in parsed request options.
Adds 7 tests covering the Octokit hook.wrap tracking pipeline: - Success path callback with correct ApiRequestInfo fields - GraphQL isGraphql detection - apiSource extraction from request metadata (the @octokit/graphql path) - resetEpochMs null when header absent - Error path callback with status code and response headers - Network failure normalized to status 500 by Octokit - Callback error swallowing (does not propagate to caller) Also extracts x-ratelimit-reset from RequestError.response.headers on error paths instead of unconditionally setting resetEpochMs to null.
- Derives ApiCallSource/ApiPool types from const arrays (single source of truth) - Uses z.enum() in Zod schemas, removing unsafe type cast - Validates apiSource in deriveSource to prevent invalid strings reaching storage - Moves SOURCE_LABELS to api-usage.ts with Record<ApiCallSource, string> exhaustiveness - Inlines checkAndResetIfExpired to single localStorage write - Removes _requestCallbacks.length guard (always populated by api-usage.ts) - Includes REST reset times in updateResetAt via Math.max - Replaces positional callback capture with invoke-all-callbacks pattern - Adds tests for guard conditions, multi-client callbacks, read-only guard, quota errors, null client path, and hermetic staleness cache
10e978c to
47e3c55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary