Skip to content

Commit

Permalink
feat: add rate limit checker
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhenry committed Jan 30, 2024
1 parent 524e6b4 commit bac1f43
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ts-backend/src/lib/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,19 @@ export const personalOctokit = (token: string) => {
});
};

export const checkRateLimit = async (octokit: Octokit) => {
const rateLimit = await octokit.rateLimit.get();
const {
core: { limit, remaining, reset },
} = rateLimit.data.resources;
const resetDate = new Date(reset * 1000);

return {
limit,
remaining,
reset,
resetDate,
};
};

export type CustomOctokit = ReturnType<typeof personalOctokit>;

0 comments on commit bac1f43

Please sign in to comment.