From bac1f43bcad10a1a4e46544a41aa82107a0c29ef Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Tue, 30 Jan 2024 14:33:20 -0500 Subject: [PATCH] feat: add rate limit checker --- ts-backend/src/lib/octokit.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ts-backend/src/lib/octokit.ts b/ts-backend/src/lib/octokit.ts index ff3a648..784ec66 100644 --- a/ts-backend/src/lib/octokit.ts +++ b/ts-backend/src/lib/octokit.ts @@ -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;