Skip to content

Commit

Permalink
Refactor: Stats card: Use typedef tags inside data fetcher (anuraghaz…
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 authored Aug 9, 2023
1 parent 20f0868 commit 72cfdf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/common/retryer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
17 changes: 13 additions & 4 deletions src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 72cfdf8

Please sign in to comment.