From cd1c246aeb2dc38b8e0d19c61a11e2e21988b2ca Mon Sep 17 00:00:00 2001 From: Aleksei Simatov Date: Thu, 19 Dec 2024 20:14:09 +0700 Subject: [PATCH] Fix: handle rate limit error (#58) * Fix: handle rate limit error * Fix: action version --- build/index.js | 18 ++++++++++++++---- package.json | 2 +- src/index.ts | 35 +++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/build/index.js b/build/index.js index 552c536..0f600fc 100644 --- a/build/index.js +++ b/build/index.js @@ -2237,8 +2237,13 @@ async function main() { core.setFailed("Inputs are invalid. Action is failed with validation error"); return; } - const rateLimitAtBeginning = await (0, getRateLimit_1.getRateLimit)(); - console.log("RATE LIMIT REMAINING BEFORE REQUESTS: ", rateLimitAtBeginning.data.rate.remaining); + try { + const rateLimitAtBeginning = await (0, getRateLimit_1.getRateLimit)(); + console.log("RATE LIMIT REMAINING BEFORE REQUESTS: ", rateLimitAtBeginning.data.rate.remaining); + } + catch (error) { + console.log("Rate limit could not be retrieved at the beginning of the action"); + } const ownersRepos = (0, requests_1.getOwnersRepositories)(); const organizationsRepos = await (0, requests_1.getOrganizationsRepositories)(); const repos = Object.keys([...ownersRepos, ...organizationsRepos].reduce((acc, element) => { @@ -2274,8 +2279,13 @@ async function main() { const preparedData = (0, converters_1.collectData)(mergedData, teams); console.log("Calculation complete. Generating markdown."); await (0, createOutput_1.createOutput)(preparedData); - const rateLimitAtEnd = await (0, getRateLimit_1.getRateLimit)(); - console.log("RATE LIMIT REMAINING AFTER REQUESTS: ", rateLimitAtEnd.data.rate.remaining); + try { + const rateLimitAtEnd = await (0, getRateLimit_1.getRateLimit)(); + console.log("RATE LIMIT REMAINING AFTER REQUESTS: ", rateLimitAtEnd.data.rate.remaining); + } + catch (error) { + console.log("Rate limit could not be retrieved at the end of the action"); + } } catch (error) { (0, analytics_1.sendActionError)(error); diff --git a/package.json b/package.json index 87f51dd..f03b547 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pull-request-analytics-action", - "version": "4.4.0", + "version": "4.4.2", "description": "Generates detailed PR analytics reports within GitHub, focusing on review efficiency and team performance.", "main": "build/index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 48e0672..b12fe83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,10 +17,7 @@ import { validate, } from "./common/utils"; import { getRateLimit } from "./requests/getRateLimit"; -import { - sendActionError, - sendActionRun, -} from "./analytics"; +import { sendActionError, sendActionRun } from "./analytics"; async function main() { try { @@ -34,11 +31,17 @@ async function main() { ); return; } - const rateLimitAtBeginning = await getRateLimit(); - console.log( - "RATE LIMIT REMAINING BEFORE REQUESTS: ", - rateLimitAtBeginning.data.rate.remaining - ); + try { + const rateLimitAtBeginning = await getRateLimit(); + console.log( + "RATE LIMIT REMAINING BEFORE REQUESTS: ", + rateLimitAtBeginning.data.rate.remaining + ); + } catch (error) { + console.log( + "Rate limit could not be retrieved at the beginning of the action" + ); + } const ownersRepos = getOwnersRepositories(); const organizationsRepos = await getOrganizationsRepositories(); @@ -93,11 +96,15 @@ async function main() { console.log("Calculation complete. Generating markdown."); await createOutput(preparedData); - const rateLimitAtEnd = await getRateLimit(); - console.log( - "RATE LIMIT REMAINING AFTER REQUESTS: ", - rateLimitAtEnd.data.rate.remaining - ); + try { + const rateLimitAtEnd = await getRateLimit(); + console.log( + "RATE LIMIT REMAINING AFTER REQUESTS: ", + rateLimitAtEnd.data.rate.remaining + ); + } catch (error) { + console.log("Rate limit could not be retrieved at the end of the action"); + } } catch (error) { sendActionError(error as Error); throw error;