From dd2668a7d7c17cb59f2b20663f43b96db911d1fe Mon Sep 17 00:00:00 2001 From: Robson Oliveira Date: Fri, 22 Dec 2023 14:30:39 -0300 Subject: [PATCH] fix(getfilecontributors): error handling --- src/utils/getFileContributors.ts | 36 ++++++++++++++++++-------------- src/utils/octokitConfig.ts | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/utils/getFileContributors.ts b/src/utils/getFileContributors.ts index 9dfe1305..e5e58dd8 100644 --- a/src/utils/getFileContributors.ts +++ b/src/utils/getFileContributors.ts @@ -15,23 +15,27 @@ export default async function getFileContributors( path: string ): Promise { const contributors: ContributorsType[] = [] - const response = await octokit.rest.repos.listCommits({ - owner, - repo, - sha: ref, - path, - }) + try { + const response = await octokit.rest.repos.listCommits({ + owner, + repo, + sha: ref, + path, + }) - response.data.forEach((commitData: any) => { - if (!contributors.find((e) => e.login === commitData.author.login)) { - contributors.push({ - name: commitData.commit.author.name, - login: commitData.author.login, - avatar: commitData.author.avatar_url, - userPage: commitData.author.html_url, - }) - } - }) + response.data.forEach((commitData: any) => { + if (!contributors.find((e) => e.login === commitData.author.login)) { + contributors.push({ + name: commitData.commit.author.name, + login: commitData.author.login, + avatar: commitData.author.avatar_url, + userPage: commitData.author.html_url, + }) + } + }) + } catch (e: any) { + console.error(e.response.data.message) + } return contributors } diff --git a/src/utils/octokitConfig.ts b/src/utils/octokitConfig.ts index 4b6b9076..903a83e7 100644 --- a/src/utils/octokitConfig.ts +++ b/src/utils/octokitConfig.ts @@ -14,6 +14,7 @@ const octokitConfig = { installationId: config.GITHUB_INSTALLATIONID, }, throttle: { + enabled: false, onRateLimit: (retryAfter: any, options: any, octokit: any) => { octokit.log.warn( `Request quota exhausted for request ${options.method} ${options.url}`