From bc9a048db9dd5541e31c38acab82c973204e0007 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 13 Sep 2024 11:12:38 +0100 Subject: [PATCH] Add more JS Docs --- utils/githubApi/fetchAllRepos.js | 12 ++++++++++++ utils/githubApi/fetchOpenPrs.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/utils/githubApi/fetchAllRepos.js b/utils/githubApi/fetchAllRepos.js index 70d9ace..1aa8df3 100644 --- a/utils/githubApi/fetchAllRepos.js +++ b/utils/githubApi/fetchAllRepos.js @@ -7,6 +7,11 @@ import { getOpenPRsForRepo, } from "../renovate/dependencyDashboard.js"; +/** + * Fetches all repos from the GitHub API. + * Each repo is enriched with data fetched through further API calls + * @returns {Promise} + */ const fetchAllRepos = async () => { const repos = []; @@ -33,10 +38,17 @@ const fetchAllRepos = async () => { return repos; }; +/** + * Fetches installation data for the app from the GitHub API + * @returns {Object} + */ const installationOctokit = await OctokitApp.app.octokit.request( "GET /app/installations" ); +/** + * Saves all repos to a JSON file + */ const saveAllRepos = async () => { console.info("Fetching all repos..."); const repos = await fetchAllRepos(); diff --git a/utils/githubApi/fetchOpenPrs.js b/utils/githubApi/fetchOpenPrs.js index 18545d6..2213b0b 100644 --- a/utils/githubApi/fetchOpenPrs.js +++ b/utils/githubApi/fetchOpenPrs.js @@ -1,5 +1,16 @@ -export const getOpenPRsForRepo = ({ octokit, repository }) => { +/** + * Requests the open PRs for a given repository + * @param {any} {octokit + * @param {any} repository} + * @returns {Promise} + */ +export const getOpenPRsForRepo = async ({ octokit, repository }) => { return octokit.request(repository.pulls_url).then(handlePrsApiResponse); }; +/** + * Returns the length of the PRs array or 0 if there are no PRs + * @param {any} {data} + * @returns {number} + */ export const handlePrsApiResponse = ({ data }) => data?.length || 0;