-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a fetch data function in a seperate file to combine the fetch …
…logic in the open-source page
- Loading branch information
Showing
6 changed files
with
52 additions
and
174 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
website/src/app/[lang]/[region]/(website)/open-source/(components)/fetch-data.ts
This file contains 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,28 @@ | ||
export async function fetchData(owner: string, repo: string, url: string) { | ||
const headers: Record<string, string> = { | ||
Accept: 'application/vnd.github+json', | ||
}; | ||
// Conditionally add the Authorization header if GITHUB_PAT is available | ||
if (process.env.GITHUB_PAT) { | ||
headers['Authorization'] = `Bearer ${process.env.GITHUB_PAT}`; | ||
} | ||
const res = await fetch(url, { | ||
headers, | ||
}); | ||
|
||
if (!res.ok) { | ||
const errorDetails = await res.text(); | ||
const status = res.status; | ||
if (status === 403) { | ||
throw new Error( | ||
'GitHub API rate limit exceeded. Please try again later or increase rate limit by authenticating.', | ||
); | ||
} else if (status === 404) { | ||
throw new Error(`GitHub repository ${owner}/${repo} not found.`); | ||
} else { | ||
throw new Error(`Failed to fetch recent commits from GitHub: ${status} - ${errorDetails}`); | ||
} | ||
} | ||
|
||
return res; | ||
} |
This file contains 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 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 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 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 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