Skip to content

Commit

Permalink
edited error messages and added fixed test mode for dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxada committed Dec 21, 2023
1 parent 3977d2e commit 93f2f5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
4 changes: 1 addition & 3 deletions providers/github/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const getUserRepositories = async (octokit) => {
} catch (error) {
return {
repositories: null,
errors: [error.message],
errors: "GitHub API returning no repository(ies).",
};
}
};
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
54 changes: 37 additions & 17 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`);
}
Expand Down

0 comments on commit 93f2f5d

Please sign in to comment.