Skip to content

refactor: route GitHub API calls through a shared useGithubQuery hook#960

Open
cleanjunc wants to merge 4 commits intoentrius:testfrom
cleanjunc:refactor/use-github-query-hook
Open

refactor: route GitHub API calls through a shared useGithubQuery hook#960
cleanjunc wants to merge 4 commits intoentrius:testfrom
cleanjunc:refactor/use-github-query-hook

Conversation

@cleanjunc
Copy link
Copy Markdown
Contributor

Summary

Adds useGithubQuery, githubFetch, and RateLimitError in src/api/ApiUtils.ts as the single sanctioned path for talking to GitHub from the UI. The hook wraps TanStack Query, forwards the query signal to axios for automatic cancellation, and converts a 403 with X-RateLimit-Remaining: 0 into a typed RateLimitError carrying the parsed X-RateLimit-Reset time. A githubErrorMessage helper renders the structured rate limit copy ("GitHub rate limit reached. Retries available at HH:MM.") while letting each site supply its own fallback for everything else.

The seven components that previously called axios.get against api.github.com or cdn.jsdelivr.net now route through the hook and drop their inline useState, useEffect, and AbortController glue:

  • RepositoryCheckTab.tsx (six parallel queries: repo, community profile, tree, three search/issues counts)
  • RepositoryCodeBrowser.tsx (repo, tree, per-path commit info with web-flow attribution preserved)
  • PRFilesChanged.tsx (PR files plus full tree, with sparse-tree fallback when the tree fetch fails)
  • MinerOpenDiscoveryIssuesByRepo.tsx (fetchGithubIssuesByAuthor + per-issue timeline lookups now thread the abort signal through githubFetch)
  • CodeViewer.tsx, ContributingViewer.tsx, ReadmeViewer.tsx (raw text fetches with responseType: 'text'; the multi-branch and multi-path fallback loops re-throw RateLimitError so the structured message is not swallowed)

The fast-click-between-PRs race on the diff viewer is gone because every site now gets cancellation for free, and rate limit failures surface with a useful message instead of a generic "Failed to load".

Related Issues

Closes #959

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (describe below)

Screenshots

Not applicable. No visual changes outside the rate limit error copy, which only renders when a 403 with X-RateLimit-Remaining: 0 is observed.

Checklist

  • New components are modularized/separated where sensible
  • Uses predefined theme (e.g. no hardcoded colors)
  • Responsive/mobile checked
  • Tested against the test API
  • npm run format and npm run lint:fix have been run
  • npm run build passes
  • Screenshots included for any UI/visual changes

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 6, 2026
@cleanjunc
Copy link
Copy Markdown
Contributor Author

@e35ventura @anderdc Could you please review this PR? Thanks!

@anderdc
Copy link
Copy Markdown
Collaborator

anderdc commented May 9, 2026

Fix conflicts.

@cleanjunc
Copy link
Copy Markdown
Contributor Author

Hi @anderdc
I've fixed the conflicts. Could you please review again?
Thanks!

@ventura-oss
Copy link
Copy Markdown
Contributor

Could you please resolve the merge conflicts so we can proceed with the review?

@cleanjunc
Copy link
Copy Markdown
Contributor Author

Hi @ventura-oss
I've fixed the conflicts. Thanks for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap GitHub API requests in a shared hook for cancellation and rate limit handling

3 participants