feat(component): display the number of requests per token left#24
Open
MatthewDaggitt wants to merge 1 commit into
Open
feat(component): display the number of requests per token left#24MatthewDaggitt wants to merge 1 commit into
MatthewDaggitt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a small UI indicator in the GitHub token form that shows the user how many GitHub API requests remain in the current hour for their token, plus when the budget resets. The data comes from a new call to GitHub's /rate_limit endpoint, plumbed through the token management hook into the existing GitHubTokenInput component.
Changes:
- New
fetchRateLimitStatusservice that hitshttps://api.github.com/rate_limitand returns thecoreremaining count and reset timestamp. useTokenManagementnow tracksrateLimitRemaining,rateLimitResetAt, andrateLimitLoading, refetching (debounced 400 ms) whenevertokenchanges.RepoAnalysisFormforwards the new state toGitHubTokenInput, which renders an "Hourly calls remaining" counter with a reset countdown.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/services/github/api.ts | Adds typed fetchRateLimitStatus helper and RateLimitStatus type that read resources.core from GitHub's rate-limit endpoint. |
| src/hooks/github/useTokenManagement.ts | Adds rate-limit state and a debounced effect that refetches when the token changes; exposes the new fields from the hook. |
| src/features/github/analysis/RepoAnalysisForm.tsx | Destructures the new rate-limit fields from the hook and passes them down to GitHubTokenInput. |
| src/components/github/forms/GitHubTokenInput.tsx | Renders the hourly-calls-remaining counter and a reset countdown next to the existing action buttons. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+10
| interface GitHubRateLimitResponse { | ||
| resources?: { | ||
| core?: { | ||
| remaining?: number; | ||
| reset?: number; | ||
| }; | ||
| }; | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
Should fix this.
Comment on lines
+41
to
+83
| useEffect(() => { | ||
| let isCancelled = false; | ||
| let timeoutId: ReturnType<typeof setTimeout> | null = null; | ||
|
|
||
| const loadRateLimit = async (): Promise<void> => { | ||
| if (!token.trim()) { | ||
| setRateLimitRemaining(null); | ||
| setRateLimitResetAt(null); | ||
| setRateLimitLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| setRateLimitLoading(true); | ||
|
|
||
| try { | ||
| const { remaining, resetAt } = await fetchRateLimitStatus(token.trim()); | ||
| if (!isCancelled) { | ||
| setRateLimitRemaining(remaining); | ||
| setRateLimitResetAt(resetAt); | ||
| } | ||
| } catch { | ||
| if (!isCancelled) { | ||
| setRateLimitRemaining(null); | ||
| setRateLimitResetAt(null); | ||
| } | ||
| } finally { | ||
| if (!isCancelled) { | ||
| setRateLimitLoading(false); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| timeoutId = setTimeout(() => { | ||
| void loadRateLimit(); | ||
| }, 400); | ||
|
|
||
| return () => { | ||
| isCancelled = true; | ||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| } | ||
| }; | ||
| }, [token]); |
Comment on lines
+34
to
+44
| const getResetCountdownText = (): string => { | ||
| if (rateLimitResetAt === null) { | ||
| return "resets soon"; | ||
| } | ||
|
|
||
| const nowInSeconds = Math.floor(Date.now() / 1000); | ||
| const remainingSeconds = Math.max(0, rateLimitResetAt - nowInSeconds); | ||
| const remainingMinutes = Math.ceil(remainingSeconds / 60); | ||
|
|
||
| return `resets in ${remainingMinutes}m`; | ||
| }; |
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.
No description provided.