From 90c415f4a7d0238a66fb1a07442dea0ec2833cec Mon Sep 17 00:00:00 2001 From: RITANKAR SAHA Date: Mon, 2 Dec 2024 13:02:57 +0530 Subject: [PATCH] Made the necessary modifications --- webiu-server/controllers/projectController.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/webiu-server/controllers/projectController.js b/webiu-server/controllers/projectController.js index 8cc8be97..76d2ca91 100644 --- a/webiu-server/controllers/projectController.js +++ b/webiu-server/controllers/projectController.js @@ -1,6 +1,10 @@ const axios = require('axios'); const accessToken = process.env.GITHUB_ACCESS_TOKEN; +if (!accessToken) { + throw new Error("GITHUB_ACCESS_TOKEN is not defined in the environment."); +} + const GITHUB_API_URL = 'https://api.github.com'; const headers = { Authorization: `token ${accessToken}`, @@ -8,10 +12,9 @@ const headers = { const getAllProjects = async (req, res) => { try { - const repositoriesResponse = await axios.get( - `${GITHUB_API_URL}/orgs/c2siorg/repos`, - { headers } - ); + const repositoriesResponse = await axios.get(`${GITHUB_API_URL}/orgs/c2siorg/repos`, { + headers, + }); const repositories = repositoriesResponse.data; const repositoriesWithPRs = await Promise.allSettled( @@ -43,8 +46,15 @@ const getAllProjects = async (req, res) => { ); const successfulProjects = repositoriesWithPRs - .filter(result => result.status === 'fulfilled') - .map(result => result.value); + .filter((result) => result.status === 'fulfilled') + .map((result) => result.value); + const failedProjects = repositoriesWithPRs + .filter((result) => result.status === 'rejected') + .map((result) => result.reason); + + if (failedProjects.length) { + console.warn(`Some repositories could not be processed:`, failedProjects); + } res.status(200).json({ repositories: successfulProjects }); } catch (error) {