Repository navigation
feat(marketing): fetch GitHub stars at build time #29555
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,25 @@ export const IOS_APP_STORE_URL = | |
| export const ANDROID_PLAY_STORE_URL = | ||
| "https://play.google.com/store/apps/details?id=com.t3tools.t3code"; | ||
|
|
||
| // Runs at build time, so each deploy picks up the current count. | ||
| async function fetchGithubStars(): Promise<string> { | ||
| const token = process.env.GITHUB_TOKEN; | ||
| try { | ||
| const response = await fetch("https://api.github.com/repos/pingdotgg/t3code", { | ||
| headers: token ? { Authorization: `Bearer ${token}` } : {}, | ||
| }); | ||
| if (!response.ok) throw new Error(`GitHub API responded ${response.status}`); | ||
| const { stargazers_count: stars } = (await response.json()) as { stargazers_count: number }; | ||
| return stars < 1000 ? String(stars) : `${Math.floor(stars / 1000)}k+`; | ||
| } catch (error) { | ||
| // A deploy must not ship a made-up count; offline dev should still render. | ||
| if (import.meta.env.PROD) throw new Error("Could not fetch GitHub stars", { cause: error }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail builds independently of If a build runs with Based on learnings: “check explicitly for the development value” and default to production-safe behavior otherwise.
|
||
| console.warn("Could not fetch GitHub stars", error); | ||
| return "?"; | ||
| } | ||
| } | ||
|
|
||
| export const MARKETING_STATS = { | ||
| githubStars: "40k+", | ||
| githubStars: await fetchGithubStars(), | ||
| users: "500,000", | ||
| } as const; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: pingdotgg/t3code
Length of output: 3713
Add a deadline to the GitHub stars request.
The request has no
signal, so a connection that stays open with no response holds the top-levelawaitinMARKETING_STATSuntil the runtime's fetch timeout ends it. Thecatchfallback runs only after that rejection. Node's globalfetchuses undici, whose defaultheadersTimeoutandbodyTimeoutare each 300 seconds. A stall therefore delays the build or dev startup by up to about five minutes per phase, not indefinitely. A request-level deadline, created at call time, bounds the whole request, including the body read inresponse.json(), and shortens that wait.Suggested fix
Committable suggestion