Skip to content

Commit

Permalink
Made the necessary modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ritankarsaha committed Dec 2, 2024
1 parent c8bd2d6 commit 90c415f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions webiu-server/controllers/projectController.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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}`,
};

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(
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 90c415f

Please sign in to comment.