From 72cfdf832da642b061433a89b183260fa2aa3316 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Wed, 9 Aug 2023 10:22:44 +0300 Subject: [PATCH] Refactor: Stats card: Use typedef tags inside data fetcher (#3056) --- src/common/retryer.js | 9 +++++++-- src/fetchers/stats-fetcher.js | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/common/retryer.js b/src/common/retryer.js index 73a7d9d388146..49d506d31531a 100644 --- a/src/common/retryer.js +++ b/src/common/retryer.js @@ -6,11 +6,16 @@ const PATs = Object.keys(process.env).filter((key) => ).length; const RETRIES = PATs ? PATs : 7; +/** + * @typedef {import("axios").AxiosResponse} AxiosResponse Axios response. + * @typedef {(variables: object, token: string) => Promise} FetcherFunction Fetcher function. + */ + /** * Try to execute the fetcher function until it succeeds or the max number of retries is reached. * - * @param {object[]} fetcher The fetcher function. - * @param {object[]} variables Object with arguments to pass to the fetcher function. + * @param {FetcherFunction} fetcher The fetcher function. + * @param {object} variables Object with arguments to pass to the fetcher function. * @param {number} retries How many times to retry. * @returns {Promise} The response from the fetcher function. */ diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 2e7996209f35a..a1e282187a756 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -74,12 +74,16 @@ const GRAPHQL_STATS_QUERY = ` } `; +/** + * @typedef {import('axios').AxiosResponse} AxiosResponse Axios response. + */ + /** * Stats fetcher object. * - * @param {import('axios').AxiosRequestHeaders} variables Fetcher variables. + * @param {object} variables Fetcher variables. * @param {string} token GitHub token. - * @returns {Promise} Stats fetcher response. + * @returns {Promise} Axios response. */ const fetcher = (variables, token) => { const query = !variables.after ? GRAPHQL_STATS_QUERY : GRAPHQL_REPOS_QUERY; @@ -98,7 +102,7 @@ const fetcher = (variables, token) => { * Fetch stats information for a given username. * * @param {string} username Github username. - * @returns {Promise} GraphQL Stats object. + * @returns {Promise} Axios response. * * @description This function supports multi-page fetching if the 'FETCH_MULTI_PAGE_STARS' environment variable is set to true. */ @@ -175,12 +179,17 @@ const totalCommitsFetcher = async (username) => { return 0; }; +/** + * @typedef {import("./types").StatsData} StatsData Stats data. + */ + /** * Fetch stats for a given username. * * @param {string} username GitHub username. * @param {boolean} include_all_commits Include all commits. - * @returns {Promise} Stats data. + * @param {string[]} exclude_repo Repositories to exclude. + * @returns {Promise} Stats data. */ const fetchStats = async ( username,