Refactor: Stats card: Use typedef tags inside data fetcher (#3056)

This commit is contained in:
Alexandr Garbuzov
2023-08-09 10:22:44 +03:00
committed by GitHub
parent 20f0868a17
commit 72cfdf832d
2 changed files with 20 additions and 6 deletions
+7 -2
View File
@@ -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<AxiosResponse>} 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<T>} The response from the fetcher function.
*/
+13 -4
View File
@@ -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<import('../common/types').Fetcher>} Stats fetcher response.
* @returns {Promise<AxiosResponse>} 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<import('../common/types').StatsFetcher>} GraphQL Stats object.
* @returns {Promise<AxiosResponse>} 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<import("./types").StatsData>} Stats data.
* @param {string[]} exclude_repo Repositories to exclude.
* @returns {Promise<StatsData>} Stats data.
*/
const fetchStats = async (
username,