diff --git a/__tests__/ratelimit.test.ts b/__tests__/ratelimit.test.ts index ca81702..64d4547 100644 --- a/__tests__/ratelimit.test.ts +++ b/__tests__/ratelimit.test.ts @@ -90,6 +90,15 @@ describe('GitHub Action - Rate Limit Handling', () => { expect(rateLimitStatus.resetTime).toEqual( expectedReset - Math.floor(Date.now() / 1000), ) + expect(rateLimitStatus.resetTimeHumanReadable).toEqual( + new Date(expectedReset * 1000).toLocaleString(), + ) + expect(core.info).toHaveBeenCalledWith( + `Rate limit remaining: ${expectedRemaining}`, + ) + expect(core.info).toHaveBeenCalledWith( + `Rate limit resets at: ${new Date(expectedReset * 1000).toLocaleString()}`, + ) }) it('should warn and stop processing if initial rate limit is exceeded', async () => { diff --git a/dist/index.js b/dist/index.js index 639718c..c8d2bba 100644 --- a/dist/index.js +++ b/dist/index.js @@ -165,10 +165,11 @@ async function checkRateLimit(octokit) { const remaining = rateLimit.data.resources.core.remaining; const reset = rateLimit.data.resources.core.reset; const now = Math.floor(Date.now() / 1000); - const resetTime = reset - now; + const resetTimeInSeconds = reset - now; + const resetTimeHumanReadable = new Date(reset * 1000).toLocaleString(); core.info(`Rate limit remaining: ${remaining}`); - core.info(`Rate limit resets in: ${resetTime} seconds`); - return { remaining, resetTime }; + core.info(`Rate limit resets at: ${resetTimeHumanReadable}`); + return { remaining, resetTime: resetTimeInSeconds, resetTimeHumanReadable }; } run(); diff --git a/src/index.ts b/src/index.ts index 2766e96..ec7e1ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -223,13 +223,15 @@ export async function checkRateLimit(octokit: ReturnType) { const rateLimit = await octokit.rest.rateLimit.get() const remaining = rateLimit.data.resources.core.remaining const reset = rateLimit.data.resources.core.reset + const now = Math.floor(Date.now() / 1000) - const resetTime = reset - now + const resetTimeInSeconds = reset - now + const resetTimeHumanReadable = new Date(reset * 1000).toLocaleString() core.info(`Rate limit remaining: ${remaining}`) - core.info(`Rate limit resets in: ${resetTime} seconds`) + core.info(`Rate limit resets at: ${resetTimeHumanReadable}`) - return { remaining, resetTime } + return { remaining, resetTime: resetTimeInSeconds, resetTimeHumanReadable } } run()