From ce4c3d5a04f132c8d8d1fd53b8eed6f76154a836 Mon Sep 17 00:00:00 2001 From: Taehyun Hwang Date: Thu, 9 May 2024 00:09:07 +0900 Subject: [PATCH] [feat] Limit get contributors api query count to 1 --- getContributors.ts | 20 +++++++------------- index.js | 32 +++++++++++++------------------- src/common/Card.ts | 10 ++++++---- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/getContributors.ts b/getContributors.ts index 600204f..4afb123 100644 --- a/getContributors.ts +++ b/getContributors.ts @@ -12,21 +12,15 @@ export async function getContributors( nameWithOwner: string, token: string, ): Promise { - const contributors: Contributor[] = []; - let page = 1; - while (true) { - const url = `https://api.github.com/repos/${nameWithOwner}/contributors?page=${page}&per_page=100`; - const response = await fetch(url, { - headers: { Authorization: `token ${token}` }, - }); + const page = 1; + const url = `https://api.github.com/repos/${nameWithOwner}/contributors?page=${page}&per_page=100`; + const response = await fetch(url, { + headers: { Authorization: `token ${token}` }, + }); - if (!response.ok) break; + if (!response.ok) return []; - const data: Contributor[] = await response.json(); - if (data.length === 0) break; + const contributors: Contributor[] = (await response.json()) as Contributor[]; - contributors.push(...data); - page++; - } return contributors; } diff --git a/index.js b/index.js index 05887a0..629390f 100644 --- a/index.js +++ b/index.js @@ -43590,21 +43590,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! node-fetch */ "./node_modules/node-fetch/src/index.js"); async function getContributors(username, nameWithOwner, token) { - const contributors = []; - let page = 1; - while (true) { - const url = `https://api.github.com/repos/${nameWithOwner}/contributors?page=${page}&per_page=100`; - const response = await (0,node_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url, { - headers: { Authorization: `token ${token}` }, - }); - if (!response.ok) - break; - const data = await response.json(); - if (data.length === 0) - break; - contributors.push(...data); - page++; - } + const url = `https://api.github.com/repos/${nameWithOwner}/contributors?page=${page}&per_page=100`; + const response = await (0,node_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url, { + headers: { Authorization: `token ${token}` }, + }); + if (!response.ok) + return []; + const contributors = (await response.json()); return contributors; } @@ -43980,7 +43972,7 @@ class Card { width="24" height="24" > - + `; const gitPRIcon = ` @@ -43997,17 +43989,19 @@ class Card { `; const githubIcon = ` - - + `; diff --git a/src/common/Card.ts b/src/common/Card.ts index 73c9d1f..3c5dd54 100644 --- a/src/common/Card.ts +++ b/src/common/Card.ts @@ -169,7 +169,7 @@ export class Card { width="24" height="24" > - + `; const gitPRIcon = ` @@ -186,17 +186,19 @@ export class Card { `; const githubIcon = ` - - + `;