Skip to content

Commit 3199eb3

Browse files
committed
fix: handle GitHub API rate limiting
1 parent 787c0ba commit 3199eb3

File tree

4 files changed

+143
-13
lines changed

4 files changed

+143
-13
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TURSO_DATABASE_URL=""
2+
TURSO_AUTH_TOKEN=""
3+
OPENAI_API_KEY=""
4+
SLACK_WEBHOOK_URL=""
5+
GITHUB_AUTH_TOKEN=""

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@astrojs/netlify": "^5.5.3",
2222
"@astrojs/tailwind": "^5.1.1",
2323
"@libsql/client": "^0.3.5",
24+
"@octokit/rest": "^21.0.2",
2425
"astro": "^4.15.12",
2526
"daisyui": "^3.9.2",
2627
"date-fns": "^2.30.0",

pnpm-lock.yaml

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/github.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
interface GitHubRelease {
2-
tag_name: string;
3-
body: string;
4-
html_url: string;
5-
}
1+
import { Octokit } from "@octokit/rest";
62

73
export async function getLatestNextjsReleases(
84
count: number,
5+
token = process.env.GITHUB_TOKEN,
96
): Promise<Array<{ version: string; body: string; url: string }>> {
10-
const response = await fetch(
11-
`https://api.github.com/repos/vercel/next.js/releases?per_page=${count}`,
12-
);
13-
if (!response.ok) {
14-
throw new Error(`GitHub API request failed: ${response.statusText}`);
15-
}
16-
const data: GitHubRelease[] = await response.json();
7+
const octokit = new Octokit({ auth: token });
8+
9+
const { data } = await octokit.repos.listReleases({
10+
owner: "vercel",
11+
repo: "next.js",
12+
per_page: count,
13+
});
14+
1715
return data.map((release) => ({
1816
version: release.tag_name,
19-
body: release.body,
17+
body: release.body ?? "",
2018
url: release.html_url,
2119
}));
2220
}

0 commit comments

Comments
 (0)