Skip to content

Fix graph ql api rate limit#632

Open
Ayush4958 wants to merge 5 commits into
JhaSourav07:mainfrom
Ayush4958:fix-graphQL-api-rate-limit
Open

Fix graph ql api rate limit#632
Ayush4958 wants to merge 5 commits into
JhaSourav07:mainfrom
Ayush4958:fix-graphQL-api-rate-limit

Conversation

@Ayush4958
Copy link
Copy Markdown

Description

I had created a proper backoff and user-facing communication for GitHub API rate limits and some additional things I encountered :- fixes a UI bug on the dashboard for loading screen, and resolves all outstanding ESLint warnings.

Fixes #523

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 27, 2026

@Ayush4958 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

👋 Hey @Ayush4958, welcome to CommitPulse! 🎉

Thanks for opening your first pull request — this is a big deal and we appreciate the effort!

While you wait for a review, please double-check:

  • ✅ You've read the CONTRIBUTING.md checklist
  • npm run lint, npm run format, and npm run test all pass locally
  • ✅ Your PR has a visual preview if it touches any SVG output
  • 💬 You've joined our Discord for faster PR feedback

A maintainer will review your PR shortly. Hang tight! 🚀

@Ayush4958
Copy link
Copy Markdown
Author

hi @JhaSourav07 ,

PR is ready for review
take time to review it

thanks

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit GitHub API rate-limit handling and user-facing feedback for the streak badge, alongside a small dashboard UI fix and cleanup in the recent-searches hook.

Changes:

  • Implement rate-limit detection/backoff in fetchWithRetry and surface a consistent rate-limit error from GitHub fetch helpers.
  • Render a dedicated “rate limited” SVG (HTTP 429) from /api/streak when rate limits are hit.
  • Fix a Tailwind className concatenation issue in the dashboard skeleton loader and simplify recent-searches localStorage handling.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/svg/generator.ts Adds generateRateLimitSVG for a dedicated rate-limit error badge.
lib/github.ts Extends retry logic to detect rate limiting and throws a dedicated rate-limit error from GitHub fetch functions.
hooks/useRecentSearches.ts Removes standalone storage helpers; storage interactions are handled inline in the hook.
components/dashboard/StatsCardSkeleton.tsx Fixes a missing space in className to restore intended styling.
app/api/streak/route.ts Detects rate-limit failures and returns a 429 response with the new rate-limit SVG + no-cache headers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/github.ts Outdated
Comment on lines +76 to +79
// Use retry-after if provided, else exponential backoff
const delay = retryAfter
? parseInt(retryAfter, 10) * 1000
: BASE_DELAY_MS * Math.pow(2, attempt);
Comment thread lib/github.ts
Comment on lines +220 to +224
if (res.status === 403 && res.headers.get('x-ratelimit-remaining') === '0') {
throw new Error('API Rate Limit Exceeded');
}
if (res.status === 429) {
throw new Error('API Rate Limit Exceeded');
Comment thread lib/github.ts
Comment on lines +68 to +72
// Check for rate limit headers
const retryAfter = res.headers.get('retry-after');
const isRateLimited =
res.status === 429 || (res.status === 403 && res.headers.get('x-ratelimit-remaining') === '0');

Comment thread app/api/streak/route.ts Outdated
Comment on lines +152 to +156
const isRateLimit = message.toLowerCase().includes('rate limit');
if (isRateLimit) {
const svg = generateRateLimitSVG(errBg, errAccent, errText, errRadius, errSpeed);
return new NextResponse(svg, {
status: 429,
Comment thread lib/svg/generator.ts
Comment on lines +698 to +704
export function generateRateLimitSVG(
bg: string,
accent: string,
text: string,
radius: number,
speed: string = '8s'
): string {
@github-actions github-actions Bot added the needs-rebase This PR has merge conflicts and needs a rebase. label May 27, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions github-actions Bot added the type:bug Something isn't working as expected label May 27, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@Aamod007
Copy link
Copy Markdown
Collaborator

@Ayush4958 do fixes according to Copilot suggestions.

@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

1 similar comment
@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@Ayush4958
Copy link
Copy Markdown
Author

Ohkk

I will be making changes accordingly to the feedback

@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

2 similar comments
@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label May 28, 2026
@github-actions
Copy link
Copy Markdown

🚨 Hey @Ayush4958, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions
Copy link
Copy Markdown

⚠️ Hey @Ayush4958, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@Ayush4958 Ayush4958 force-pushed the fix-graphQL-api-rate-limit branch from b3624fc to 53844f6 Compare May 28, 2026 06:08
@Ayush4958 Ayush4958 force-pushed the fix-graphQL-api-rate-limit branch from 53844f6 to 35b11e9 Compare May 28, 2026 06:27
@github-actions github-actions Bot removed status:blocked This PR is blocked due to a failing CI check. needs-rebase This PR has merge conflicts and needs a rebase. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: GraphQL API rate limits not gracefully handled for power users

3 participants