Skip to content

Commit afaf693

Browse files
authored
docs(github): add JSDoc comments for fetch utility functions (JhaSourav07#772)
## Description Added JSDoc documentation for the public GitHub fetch utility functions in `lib/github.ts`. ### Changes made * Added documentation for all three exported fetch functions * Added `@param`, `@returns`, `@throws`, and `@example` tags * Documented `FetchOptions` fields including `bypassCache`, `from`, and `to` * Added notes about retry behavior and possible error responses * No functional changes Fixes JhaSourav07#311 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1107" height="887" alt="image" src="https://github.com/user-attachments/assets/fe328081-21fd-40c1-9414-3e2dafbf4944" /> <img width="1298" height="895" alt="image" src="https://github.com/user-attachments/assets/3c99c7e0-8394-46be-bcf5-7f271d2dccb7" /> ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 08d93bb + a359b65 commit afaf693

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

@@ -159,6 +179,35 @@ export function displayName(profile: GitHubUserProfile): string {
159179
return profile.login;
160180
}
161181

182+
/**
183+
* Fetches a user's GitHub contribution calendar using the GitHub GraphQL API.
184+
*
185+
* Requests are automatically retried on rate limiting (429) and server errors (5xx)
186+
* using exponential backoff.
187+
*
188+
* @param username - GitHub username to fetch contributions for.
189+
* @param options - Optional fetch configuration.
190+
* @param options.bypassCache - Forces a fresh API request instead of using cached data.
191+
* @param options.from - Start date for contribution filtering.
192+
* @param options.to - End date for contribution filtering.
193+
* @param options.signal - Optional AbortSignal used to cancel the request.
194+
*
195+
* @returns A promise resolving to the user's contribution calendar.
196+
*
197+
* @throws {Error} If the GitHub PAT is missing or invalid.
198+
* @throws {Error} If the GitHub user cannot be found.
199+
* @throws {Error} If the GitHub API request fails after all retry attempts.
200+
* @throws {Error} If the request times out or is aborted.
201+
*
202+
* @example
203+
* ```ts
204+
* const calendar = await fetchGitHubContributions("octocat", {
205+
* from: "2025-01-01",
206+
* to: "2025-12-31",
207+
* bypassCache: true,
208+
* });
209+
* ```
210+
*/
162211
export async function fetchGitHubContributions(
163212
username: string,
164213
options: FetchOptions = {}
@@ -232,6 +281,32 @@ export async function fetchGitHubContributions(
232281
return calendar;
233282
}
234283

284+
/**
285+
* Fetches public GitHub profile information for a user.
286+
*
287+
* Requests are automatically retried on rate limiting (429) and server errors (5xx)
288+
* using exponential backoff.
289+
*
290+
* @param username - GitHub username to fetch profile data for.
291+
* @param options - Optional fetch configuration.
292+
* @param options.bypassCache - Forces a fresh API request instead of using cached data.
293+
* @param options.signal - Optional AbortSignal used to cancel the request.
294+
*
295+
* @returns A promise resolving to the user's GitHub profile data.
296+
*
297+
* @throws {Error} If the GitHub user cannot be found.
298+
* @throws {Error} If the GitHub REST API request fails.
299+
* @throws {Error} If the request times out or is aborted.
300+
*
301+
* @example
302+
* ```ts
303+
* const controller = new AbortController();
304+
*
305+
* const profile = await fetchUserProfile("octocat", {
306+
* signal: controller.signal,
307+
* });
308+
* ```
309+
*/
235310
export async function fetchUserProfile(
236311
username: string,
237312
options: FetchOptions = {}
@@ -269,6 +344,32 @@ export async function fetchUserProfile(
269344
return profile;
270345
}
271346

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

0 commit comments

Comments
 (0)