From 93f2f5deef58e30425701afd945168d5c2cdefab Mon Sep 17 00:00:00 2001 From: kaxada Date: Thu, 21 Dec 2023 10:39:09 +0300 Subject: [PATCH] edited error messages and added fixed test mode for dev --- providers/github/APICalls.js | 4 +-- routes/index.js | 54 ++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/providers/github/APICalls.js b/providers/github/APICalls.js index 0b58df5..594bd0c 100644 --- a/providers/github/APICalls.js +++ b/providers/github/APICalls.js @@ -71,7 +71,7 @@ const getUserRepositories = async (octokit) => { } catch (error) { return { repositories: null, - errors: [error.message], + errors: "GitHub API returning no repository(ies).", }; } }; @@ -137,7 +137,6 @@ const getFileContentAndSHA = async (octokit, repositoryFullName, filePath) => { }; } }; - /** * Scans a list of repositories to try and apply for a badge * @param {*} userId Id of the user @@ -159,7 +158,6 @@ const scanRepositories = async (userId, name, email, repositoryIds) => { console.error(info_errors); continue; } - const { file, errors: file_errors } = await getFileContentAndSHA( octokit, info.fullName, diff --git a/routes/index.js b/routes/index.js index 190d33c..9338ac2 100644 --- a/routes/index.js +++ b/routes/index.js @@ -31,7 +31,6 @@ const reposToBadge = async (req, res) => { const userId = req.body.userId; const provider = req.body.provider; const repositoryIds = selectedRepos.map((repo) => repo.id); - if (!provider) { res.status(400).send("provider missing"); return; @@ -55,22 +54,43 @@ const reposToBadge = async (req, res) => { } // Process the selected repos as needed - if (provider === "github") { - const results = await github_helpers.scanRepositories( - user.id, - user.name, - user.email, - repositoryIds - ); - res.status(200).json({ results }); - } else if (provider === "gitlab") { - const results = await gitlab_helpers.scanRepositories( - user.id, - user.name, - user.email, - repositoryIds - ); - res.status(200).json({ results }); + if (process.env.NODE_ENV === "development") { + if (provider === "github") { + const results = await github_helpers.scanRepositories( + user.id, + user.name, + user.email, + selectedRepos + ); + res.status(200).json({ results }); + } else if (provider === "gitlab") { + const results = await gitlab_helpers.scanRepositories( + user.id, + user.name, + user.email, + selectedRepos + ); + res.status(200).json({ results }); + } + } else if (process.env.NODE_ENV === "production") { + // process the selected repositories in production + if (provider === "github") { + const results = await github_helpers.scanRepositories( + user.id, + user.name, + user.email, + repositoryIds + ); + res.status(200).json({ results }); + } else if (provider === "gitlab") { + const results = await gitlab_helpers.scanRepositories( + user.id, + user.name, + user.email, + repositoryIds + ); + res.status(200).json({ results }); + } } else { res.status(400).send(`Unknown provider: ${provider}`); }