Skip to content

Commit a359b65

Browse files
author
tamilr0727-ux
committed
docs(github): add JSDoc comments for fetch utility functions
1 parent b7e5611 commit a359b65

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

lib/github.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,30 @@ type GitHubContributionResponse = {
9292
errors?: Array<{ message: string }>;
9393
};
9494

95+
/**
96+
* Configuration options for GitHub API fetch requests.
97+
*/
9598
type FetchOptions = {
99+
/**
100+
* Skips the in-memory cache and forces a fresh GitHub API request.
101+
*/
96102
bypassCache?: boolean;
103+
104+
/**
105+
* Start date used for filtering contribution data.
106+
* Expected format: YYYY-MM-DD.
107+
*/
97108
from?: string;
109+
110+
/**
111+
* End date used for filtering contribution data.
112+
* Expected format: YYYY-MM-DD.
113+
*/
98114
to?: string;
115+
116+
/**
117+
* Optional AbortSignal used to cancel the request.
118+
*/
99119
signal?: AbortSignal;
100120
};
101121

@@ -148,6 +168,35 @@ export function displayName(profile: GitHubUserProfile): string {
148168
return profile.login;
149169
}
150170

171+
/**
172+
* Fetches a user's GitHub contribution calendar using the GitHub GraphQL API.
173+
*
174+
* Requests are automatically retried on rate limiting (429) and server errors (5xx)
175+
* using exponential backoff.
176+
*
177+
* @param username - GitHub username to fetch contributions for.
178+
* @param options - Optional fetch configuration.
179+
* @param options.bypassCache - Forces a fresh API request instead of using cached data.
180+
* @param options.from - Start date for contribution filtering.
181+
* @param options.to - End date for contribution filtering.
182+
* @param options.signal - Optional AbortSignal used to cancel the request.
183+
*
184+
* @returns A promise resolving to the user's contribution calendar.
185+
*
186+
* @throws {Error} If the GitHub PAT is missing or invalid.
187+
* @throws {Error} If the GitHub user cannot be found.
188+
* @throws {Error} If the GitHub API request fails after all retry attempts.
189+
* @throws {Error} If the request times out or is aborted.
190+
*
191+
* @example
192+
* ```ts
193+
* const calendar = await fetchGitHubContributions("octocat", {
194+
* from: "2025-01-01",
195+
* to: "2025-12-31",
196+
* bypassCache: true,
197+
* });
198+
* ```
199+
*/
151200
export async function fetchGitHubContributions(
152201
username: string,
153202
options: FetchOptions = {}
@@ -221,6 +270,32 @@ export async function fetchGitHubContributions(
221270
return calendar;
222271
}
223272

273+
/**
274+
* Fetches public GitHub profile information for a user.
275+
*
276+
* Requests are automatically retried on rate limiting (429) and server errors (5xx)
277+
* using exponential backoff.
278+
*
279+
* @param username - GitHub username to fetch profile data for.
280+
* @param options - Optional fetch configuration.
281+
* @param options.bypassCache - Forces a fresh API request instead of using cached data.
282+
* @param options.signal - Optional AbortSignal used to cancel the request.
283+
*
284+
* @returns A promise resolving to the user's GitHub profile data.
285+
*
286+
* @throws {Error} If the GitHub user cannot be found.
287+
* @throws {Error} If the GitHub REST API request fails.
288+
* @throws {Error} If the request times out or is aborted.
289+
*
290+
* @example
291+
* ```ts
292+
* const controller = new AbortController();
293+
*
294+
* const profile = await fetchUserProfile("octocat", {
295+
* signal: controller.signal,
296+
* });
297+
* ```
298+
*/
224299
export async function fetchUserProfile(
225300
username: string,
226301
options: FetchOptions = {}
@@ -258,6 +333,32 @@ export async function fetchUserProfile(
258333
return profile;
259334
}
260335

336+
/**
337+
* Fetches public repositories for a GitHub user.
338+
*
339+
* Repository data is fetched from the GitHub REST API with automatic retries
340+
* for rate limiting (429) and server errors (5xx).
341+
*
342+
* Results are paginated with a maximum limit of 300 repositories
343+
* across 3 API pages.
344+
*
345+
* @param username - GitHub username to fetch repositories for.
346+
* @param options - Optional fetch configuration.
347+
* @param options.bypassCache - Forces a fresh API request instead of using cached data.
348+
* @param options.signal - Optional AbortSignal used to cancel the request.
349+
*
350+
* @returns A promise resolving to an array of GitHub repositories.
351+
*
352+
* @throws {Error} If the GitHub API request fails after all retry attempts.
353+
* @throws {Error} If the request times out or is aborted.
354+
*
355+
* @example
356+
* ```ts
357+
* const repos = await fetchUserRepos("octocat");
358+
*
359+
* console.log(repos.length);
360+
* ```
361+
*/
261362
export async function fetchUserRepos(
262363
username: string,
263364
options: FetchOptions = {}

0 commit comments

Comments
 (0)