-
Notifications
You must be signed in to change notification settings - Fork 63
Handle GitHub API deprecations + Contributors/Profile fix #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ASR1015
wants to merge
21
commits into
GitMetricsLab:main
Choose a base branch
from
ASR1015:fix/github-api-version-warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1ffe964
fix: add GitHub API version header, PAT usage, router cleanup; contri…
ASR1015 1985c85
perf(router): lazy-load routes + suspense fallback
ASR1015 df1f6b0
feat: add ghJson helper for API error handling
ASR1015 f594f4e
fix: handle GitHub API deprecations + robust profile/PR fetching
ASR1015 d367be4
fix: migrate /search/issues to GraphQL + improve error handling
ASR1015 5b67ede
fix: await clipboard write for reliable copy + error handling
ASR1015 9bc8d72
fix: leverage resolveRepoFullName with fallback in Contributors page
ASR1015 60a8c64
fix(router): remove duplicate RouterProvider and export router config…
ASR1015 74eee8f
feat: migrate Tracker to GraphQL search, add missing fields, better e…
ASR1015 14bfce2
fix(github-data): improve GraphQL query with correct fields, paginati…
ASR1015 232cfe9
fix: map GitHub response to Tracker fields + cache endCursor
ASR1015 7ba06b2
fix: align PR.id with GraphQL databaseId
ASR1015 949406a
fix: align PR GraphQL fields with Tracker requirements (databaseId, r…
ASR1015 b8a87eb
fix(contributors): handle 204 No Content to avoid JSON parse error
ASR1015 1d3341a
types: make GitHub cursor paging type-safe (SearchType + typed cursor…
ASR1015 3e82610
fix(search): key GraphQL pagination cursors by username+page size to …
ASR1015 b90005a
fix(profile): map GraphQL PR nodes to local PR shape + handle GraphQL…
ASR1015 b5b4b5e
octokit: use shared API version/base, skip empty auth, add Accept hea…
ASR1015 58bbb99
fix: always tag PRs with pull_request; avoid misclassifying open PRs …
ASR1015 47f8948
feat(contributors): type Contributor, DRY token, unmount-safe state u…
ASR1015 5847da2
feat(contributors): type Contributor, DRY token, unmount-safe state u…
ASR1015 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // src/lib/githubFetch.ts | ||
| export const GITHUB_API_VERSION = "2022-11-28"; | ||
|
|
||
| export async function ghFetch( | ||
| path: string, | ||
| token: string, | ||
| init: RequestInit = {} | ||
| ) { | ||
| const base = "https://api.github.com"; | ||
| const headers = new Headers(init.headers || {}); | ||
| if (token) { | ||
| headers.set("Authorization", `Bearer ${token}`); // or `token ${token}` | ||
| } | ||
| headers.set("Accept", "application/vnd.github+json"); | ||
| headers.set("X-GitHub-Api-Version", GITHUB_API_VERSION); | ||
|
|
||
| return fetch(`${base}${path}`, { ...init, headers }); | ||
| } | ||
|
|
||
| export async function ghJson<T>( | ||
| path: string, | ||
| token: string, | ||
| init: RequestInit = {} | ||
| ): Promise<T> { | ||
| const res = await ghFetch(path, token, init); | ||
| if (!res.ok) { | ||
| const text = await res.text().catch(() => ""); | ||
| throw new Error( | ||
| `GitHub API ${res.status} ${res.statusText}${text ? `: ${text}` : ""}` | ||
| ); | ||
| } | ||
| return res.json() as Promise<T>; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Octokit } from "@octokit/core"; | ||
| import { paginateRest } from "@octokit/plugin-paginate-rest"; | ||
| import { throttling } from "@octokit/plugin-throttling"; | ||
| import { GITHUB_API_VERSION, GITHUB_API_BASE } from "../utils/constants"; | ||
|
|
||
| const MyOctokit = Octokit.plugin(paginateRest, throttling); | ||
|
|
||
| // Make token optional; when empty/undefined we avoid sending an empty Authorization header | ||
| export const makeOctokit = (token?: string) => | ||
| new MyOctokit({ | ||
| auth: token || undefined, | ||
| baseUrl: GITHUB_API_BASE, | ||
| userAgent: "github-tracker/1.0", | ||
| request: { | ||
| // IMPORTANT: stops “deprecated / unversioned” warnings and aligns with fetch helpers | ||
| headers: { | ||
| Accept: "application/vnd.github+json", | ||
| "X-GitHub-Api-Version": GITHUB_API_VERSION, | ||
| }, | ||
| }, | ||
| throttle: { | ||
| // Retry once on primary rate limit, then surface to caller | ||
| onRateLimit: (retryAfter, options, octokit, retryCount?: number) => { | ||
| const count = retryCount ?? 0; | ||
| if (count === 0) { | ||
| console.warn( | ||
| `Rate Limit: ${options.method} ${options.url}. Retrying in ${retryAfter}s.` | ||
| ); | ||
| return true; // single retry | ||
| } | ||
| return false; | ||
| }, | ||
| // Retry once on secondary rate limit as well | ||
| onSecondaryRateLimit: (_retryAfter, options) => { | ||
| console.warn( | ||
| `Secondary rate limit: ${options.method} ${options.url}.` | ||
| ); | ||
| return true; // single retry | ||
| }, | ||
| }, | ||
| }); | ||
ASR1015 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.