Skip to content

feat(component): display the number of requests per token left#24

Open
MatthewDaggitt wants to merge 1 commit into
mainfrom
token-limit
Open

feat(component): display the number of requests per token left#24
MatthewDaggitt wants to merge 1 commit into
mainfrom
token-limit

Conversation

@MatthewDaggitt

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings May 14, 2026 02:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fetchRateLimitStatus service that hits https://api.github.com/rate_limit and returns the core remaining count and reset timestamp.
  • useTokenManagement now tracks rateLimitRemaining, rateLimitResetAt, and rateLimitLoading, refetching (debounced 400 ms) whenever token changes.
  • RepoAnalysisForm forwards the new state to GitHubTokenInput, 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;
};
};
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants