From 519890de3ae22354bd521a7806d11af3e6d34425 Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Tue, 20 Feb 2024 17:38:35 +0530 Subject: [PATCH 1/7] fix: remove canvas-editor parent Collaborators --- updateProject.mjs | 298 +++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 176 deletions(-) diff --git a/updateProject.mjs b/updateProject.mjs index 58de6a15..7f70e08c 100644 --- a/updateProject.mjs +++ b/updateProject.mjs @@ -6,206 +6,152 @@ import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -async function getCurrentProjects() { - const query = `query getCurrentProjects { - foss_projects(filter: {project_type: { _eq: "current" }}) { - id, - title, - short_description, - github_repository_link, - documentation_link, - project_type, - date_created, - date_updated, - status, - } - }`; - - try { - process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; - - const response = await fetch("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: query, - }), - }); - - if (response.ok) { - const { data } = await response.json(); - data.foss_projects.forEach((entry) => { - entry.id = parseInt(entry.id); - entry.shortDescription = entry.short_description; - entry.githubUrl = entry.github_repository_link; - entry.documentationUrl = entry.documentation_link; - - delete entry.short_description; - delete entry.github_repository_link; - delete entry.documentation_link; - }); - - const projectsJsonPath = path.join( - __dirname, - "src/app/projects/assets/projects.json" - ); - - fs.writeFileSync( - projectsJsonPath, - JSON.stringify(data.foss_projects, null, 2) - ); - - console.log("Projects updated successfully."); - } else { - console.log("API is not available. Using existing JSON."); - } - } catch (error) { - console.log(error); +// Function to fetch data from an API endpoint +async function fetchData(url, options) { + const response = await fetch(url, options); + if (!response.ok) { + throw new Error(`Request failed with status: ${response.status}`); } + return await response.json(); } -async function getUpcomingProjects() { - const query = `query getUpcomingProjects { - foss_projects(filter: {project_type: { _eq: "upcoming" }}) { - id, - title, - short_description, - github_repository_link, - documentation_link, - project_type, - date_created, - date_updated, - status, - } - }`; - - try { - process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; - - const response = await fetch("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: query, - }), - }); - - if (response.ok) { - const { data } = await response.json(); - data.foss_projects.forEach((entry) => { - entry.id = parseInt(entry.id); - entry.shortDescription = entry.short_description; - entry.githubUrl = entry.github_repository_link; - entry.documentationUrl = entry.documentation_link; - - delete entry.short_description; - delete entry.github_repository_link; - delete entry.documentation_link; - }); - - const projectsJsonPath = path.join( - __dirname, - "src/app/projects/assets/upcomingProjects.json" - ); - - fs.writeFileSync( - projectsJsonPath, - JSON.stringify(data.foss_projects, null, 2) - ); +// Function to fetch collaborators from GitHub +async function fetchCollaborators(url, githubToken) { + const options = { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + }; + return await fetchData(url, options); +} - console.log("Upcoming projects updated successfully."); - } else { - console.log("API is not available. Using existing JSON."); - } - } catch (error) { - console.log(error); +// Function to get collaborators of a repository +async function getCollaborators(repoData, githubToken) { + + if (repoData.fork && repoData.parent?.contributors_url) { + // If the repository is a fork and has a parent, fetch collaborators from both + const [c1, c2] = await Promise.all([ + fetchCollaborators(repoData.contributors_url, githubToken), + fetchCollaborators(repoData.parent.contributors_url, githubToken) + ]); + // Filter out collaborators from the repository who are also in the parent + return c1.filter(collab1 => !c2.some(collab2 => collab1.login === collab2.login)); } + // Otherwise, fetch collaborators directly from the repository + return fetchCollaborators(repoData.contributors_url, githubToken); } -//get list of contributors from github repo -async function getContributorsList() { - const githubApiUrl = "https://api.github.com/users/mindfiredigital/repos"; +// Main function to update projects data +async function updateProjects() { const githubToken = process.env.GITHUB_TOKEN; - console.log("my github token", githubToken); try { - const github_response = await fetch(githubApiUrl, { - method: "GET", - headers: { - Authorization: `token ${githubToken}`, - Accept: "application/vnd.github.v3+json", - }, - }); - - if (!github_response.ok) { - throw new Error( - `Failed to fetch repositories. Status: ${github_response.status}` - ); - } - const repositories = await github_response.json(); - const repoNames = repositories.map((repo) => repo.name); - + process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; + // Fetch data for current projects and upcoming projects + const [currentProjectsData, upcomingProjectsData, repositories] = await Promise.all([ + // Fetch current projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getCurrentProjects { + foss_projects(filter: {project_type: { _eq: "current" }}) { + id, + title, + short_description, + github_repository_link, + documentation_link, + project_type, + date_created, + date_updated, + status, + } + }` + }), + }), + // Fetch upcoming projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getUpcomingProjects { + foss_projects(filter: {project_type: { _eq: "upcoming" }}) { + id, + title, + short_description, + github_repository_link, + documentation_link, + project_type, + date_created, + date_updated, + status, + } + }` + }), + }), + // Fetch repositories data from GitHub + fetchData("https://api.github.com/users/mindfiredigital/repos", { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + }) + ]); + + // Process and write data for current projects + const currentProjects = currentProjectsData.data.foss_projects.map(entry => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + })); + fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/projects.json"), JSON.stringify(currentProjects, null, 2)); + console.log("Current projects updated successfully."); + + // Process and write data for upcoming projects + const upcomingProjects = upcomingProjectsData.data.foss_projects.map(entry => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + })); + fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/upcomingProjects.json"), JSON.stringify(upcomingProjects, null, 2)); + console.log("Upcoming projects updated successfully."); + + // Fetch and process contributors data for repositories + const repoNames = repositories.map(repo => repo.name); const contributorsObject = {}; for (const repoName of repoNames) { - const repoContributorsUrl = `https://api.github.com/repos/mindfiredigital/${repoName}/contributors`; - - const contributorsResponse = await fetch(repoContributorsUrl, { - method: "GET", + const repoData = await fetchData(`https://api.github.com/repos/mindfiredigital/${repoName}`, { headers: { Authorization: `token ${githubToken}`, Accept: "application/vnd.github.v3+json", }, - }); - - if (!contributorsResponse.ok) { - console.error( - `Failed to fetch contributors for ${repoName}. Status: ${contributorsResponse.status}` - ); - continue; - } - - const contributors = await contributorsResponse.json(); - contributorsObject[repoName] = contributors; + }) + contributorsObject[repoName] = await getCollaborators(repoData, githubToken); } - let contributionsMap = {}; - for (let repo in contributorsObject) { - contributorsObject[repo].forEach((contributor) => { + // Aggregate contributor from contributors + const contributionsMap = {}; + for (const repo in contributorsObject) { + contributorsObject[repo].forEach(contributor => { const { login, contributions, id, avatar_url, html_url } = contributor; - if (contributionsMap.hasOwnProperty(login)) { - contributionsMap[login].contributions += contributions; - } else { - contributionsMap[login] = { - id, - contributions, - html_url, - avatar_url, - login, - }; - } + contributionsMap[login] = contributionsMap[login] || { id, contributions: 0, html_url, avatar_url, login }; + contributionsMap[login].contributions += contributions; }); } - let sortedContributions = Object.fromEntries( - Object.entries(contributionsMap).sort( - ([, a], [, b]) => b.contributions - a.contributions - ) - ); - - const projectsJsonPath = path.join( - __dirname, - "src/app/projects/assets/contributors.json" - ); - fs.writeFileSync( - projectsJsonPath, - JSON.stringify(sortedContributions, null, 2) - ); + // Sort contributions and write data to file + const sortedContributions = Object.values(contributionsMap).sort((a, b) => b.contributions - a.contributions); + fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/contributors.json"), JSON.stringify(sortedContributions, null, 2)); console.log("Contributors list updated successfully."); } catch (error) { - console.log(error); + console.error("An error occurred:", error); } } -getCurrentProjects(); -getUpcomingProjects(); -getContributorsList(); +// Call the main function +updateProjects(); From dc147efeb5d8ecb4ec4fa0b21e745c566511e301 Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Wed, 21 Feb 2024 16:46:27 +0530 Subject: [PATCH 2/7] feat: add the code to remove github-actions[bot] --- updateProject.mjs | 160 +++++++++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 60 deletions(-) diff --git a/updateProject.mjs b/updateProject.mjs index 7f70e08c..de82015f 100644 --- a/updateProject.mjs +++ b/updateProject.mjs @@ -28,15 +28,16 @@ async function fetchCollaborators(url, githubToken) { // Function to get collaborators of a repository async function getCollaborators(repoData, githubToken) { - if (repoData.fork && repoData.parent?.contributors_url) { // If the repository is a fork and has a parent, fetch collaborators from both const [c1, c2] = await Promise.all([ fetchCollaborators(repoData.contributors_url, githubToken), - fetchCollaborators(repoData.parent.contributors_url, githubToken) + fetchCollaborators(repoData.parent.contributors_url, githubToken), ]); // Filter out collaborators from the repository who are also in the parent - return c1.filter(collab1 => !c2.some(collab2 => collab1.login === collab2.login)); + return c1.filter( + (collab1) => !c2.some((collab2) => collab1.login === collab2.login) + ); } // Otherwise, fetch collaborators directly from the repository return fetchCollaborators(repoData.contributors_url, githubToken); @@ -44,18 +45,21 @@ async function getCollaborators(repoData, githubToken) { // Main function to update projects data async function updateProjects() { - const githubToken = process.env.GITHUB_TOKEN; + // const githubToken = process.env.GITHUB_TOKEN; + const githubToken = + "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"; try { process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; // Fetch data for current projects and upcoming projects - const [currentProjectsData, upcomingProjectsData, repositories] = await Promise.all([ - // Fetch current projects data - fetchData("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: `query getCurrentProjects { + const [currentProjectsData, upcomingProjectsData, repositories] = + await Promise.all([ + // Fetch current projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getCurrentProjects { foss_projects(filter: {project_type: { _eq: "current" }}) { id, title, @@ -67,15 +71,15 @@ async function updateProjects() { date_updated, status, } - }` + }`, + }), }), - }), - // Fetch upcoming projects data - fetchData("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: `query getUpcomingProjects { + // Fetch upcoming projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getUpcomingProjects { foss_projects(filter: {project_type: { _eq: "upcoming" }}) { id, title, @@ -87,66 +91,102 @@ async function updateProjects() { date_updated, status, } - }` + }`, + }), }), - }), - // Fetch repositories data from GitHub - fetchData("https://api.github.com/users/mindfiredigital/repos", { - headers: { - Authorization: `token ${githubToken}`, - Accept: "application/vnd.github.v3+json", - }, - }) - ]); + // Fetch repositories data from GitHub + fetchData("https://api.github.com/users/mindfiredigital/repos", { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + }), + ]); // Process and write data for current projects - const currentProjects = currentProjectsData.data.foss_projects.map(entry => ({ - ...entry, - id: parseInt(entry.id), - shortDescription: entry.short_description, - githubUrl: entry.github_repository_link, - documentationUrl: entry.documentation_link, - })); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/projects.json"), JSON.stringify(currentProjects, null, 2)); + const currentProjects = currentProjectsData.data.foss_projects.map( + (entry) => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + }) + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/projects.json"), + JSON.stringify(currentProjects, null, 2) + ); console.log("Current projects updated successfully."); // Process and write data for upcoming projects - const upcomingProjects = upcomingProjectsData.data.foss_projects.map(entry => ({ - ...entry, - id: parseInt(entry.id), - shortDescription: entry.short_description, - githubUrl: entry.github_repository_link, - documentationUrl: entry.documentation_link, - })); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/upcomingProjects.json"), JSON.stringify(upcomingProjects, null, 2)); + const upcomingProjects = upcomingProjectsData.data.foss_projects.map( + (entry) => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + }) + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/upcomingProjects.json"), + JSON.stringify(upcomingProjects, null, 2) + ); console.log("Upcoming projects updated successfully."); // Fetch and process contributors data for repositories - const repoNames = repositories.map(repo => repo.name); + const repoNames = repositories.map((repo) => repo.name); const contributorsObject = {}; for (const repoName of repoNames) { - const repoData = await fetchData(`https://api.github.com/repos/mindfiredigital/${repoName}`, { - headers: { - Authorization: `token ${githubToken}`, - Accept: "application/vnd.github.v3+json", - }, - }) - contributorsObject[repoName] = await getCollaborators(repoData, githubToken); + const repoData = await fetchData( + `https://api.github.com/repos/mindfiredigital/${repoName}`, + { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + } + ); + contributorsObject[repoName] = await getCollaborators( + repoData, + githubToken + ); } // Aggregate contributor from contributors const contributionsMap = {}; + for (const repo in contributorsObject) { - contributorsObject[repo].forEach(contributor => { - const { login, contributions, id, avatar_url, html_url } = contributor; - contributionsMap[login] = contributionsMap[login] || { id, contributions: 0, html_url, avatar_url, login }; - contributionsMap[login].contributions += contributions; - }); + if (contributorsObject.hasOwnProperty(repo)) { + contributorsObject[repo].forEach((contributor) => { + if (contributor.login === "github-actions[bot]") { + // Skip processing GitHub Actions bot contributions + return; + } + const { login, contributions, id, avatar_url, html_url } = + contributor; + // Update contributions map + contributionsMap[login] = { + id, + contributions: + (contributionsMap[login]?.contributions || 0) + contributions, + html_url, + avatar_url, + login, + }; + }); + } } // Sort contributions and write data to file - const sortedContributions = Object.values(contributionsMap).sort((a, b) => b.contributions - a.contributions); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/contributors.json"), JSON.stringify(sortedContributions, null, 2)); + const sortedContributions = Object.values(contributionsMap).sort( + (a, b) => b.contributions - a.contributions + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/contributors.json"), + JSON.stringify(sortedContributions, null, 2) + ); console.log("Contributors list updated successfully."); } catch (error) { console.error("An error occurred:", error); From 08eea9daa0458069e450734a4b7fb03a6d78ee01 Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Wed, 21 Feb 2024 16:50:55 +0530 Subject: [PATCH 3/7] fix: set the git token --- updateProject.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/updateProject.mjs b/updateProject.mjs index de82015f..fc27f251 100644 --- a/updateProject.mjs +++ b/updateProject.mjs @@ -45,9 +45,7 @@ async function getCollaborators(repoData, githubToken) { // Main function to update projects data async function updateProjects() { - // const githubToken = process.env.GITHUB_TOKEN; - const githubToken = - "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"; + const githubToken = process.env.GITHUB_TOKEN; try { process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; From 1b42c208dbb7734965fc7180dcd1b17e03ec7f49 Mon Sep 17 00:00:00 2001 From: praliptarajoo Date: Thu, 22 Feb 2024 11:58:47 +0530 Subject: [PATCH 4/7] chore: readme file updated --- README.md | 1 + updateProject.mjs | 141 ++++++++++++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index f4d03228..aa285670 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,4 @@ bun start:build - [avishekthapamindfire0822](https://github.com/avishekthapamindfire0822) - [ArnabKMindfire](https://github.com/ArnabKMindfire) - [praliptarajoo](https://github.com/praliptarajoo) +- [ashutosh-jena-mindfire](https://github.com/ashutosh-jena-mindfire) diff --git a/updateProject.mjs b/updateProject.mjs index 7f70e08c..c85e36ad 100644 --- a/updateProject.mjs +++ b/updateProject.mjs @@ -28,15 +28,16 @@ async function fetchCollaborators(url, githubToken) { // Function to get collaborators of a repository async function getCollaborators(repoData, githubToken) { - if (repoData.fork && repoData.parent?.contributors_url) { // If the repository is a fork and has a parent, fetch collaborators from both const [c1, c2] = await Promise.all([ fetchCollaborators(repoData.contributors_url, githubToken), - fetchCollaborators(repoData.parent.contributors_url, githubToken) + fetchCollaborators(repoData.parent.contributors_url, githubToken), ]); // Filter out collaborators from the repository who are also in the parent - return c1.filter(collab1 => !c2.some(collab2 => collab1.login === collab2.login)); + return c1.filter( + (collab1) => !c2.some((collab2) => collab1.login === collab2.login) + ); } // Otherwise, fetch collaborators directly from the repository return fetchCollaborators(repoData.contributors_url, githubToken); @@ -49,13 +50,14 @@ async function updateProjects() { try { process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; // Fetch data for current projects and upcoming projects - const [currentProjectsData, upcomingProjectsData, repositories] = await Promise.all([ - // Fetch current projects data - fetchData("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: `query getCurrentProjects { + const [currentProjectsData, upcomingProjectsData, repositories] = + await Promise.all([ + // Fetch current projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getCurrentProjects { foss_projects(filter: {project_type: { _eq: "current" }}) { id, title, @@ -67,15 +69,15 @@ async function updateProjects() { date_updated, status, } - }` + }`, + }), }), - }), - // Fetch upcoming projects data - fetchData("https://directus.ourgoalplan.co.in/graphql", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - query: `query getUpcomingProjects { + // Fetch upcoming projects data + fetchData("https://directus.ourgoalplan.co.in/graphql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: `query getUpcomingProjects { foss_projects(filter: {project_type: { _eq: "upcoming" }}) { id, title, @@ -87,66 +89,93 @@ async function updateProjects() { date_updated, status, } - }` + }`, + }), }), - }), - // Fetch repositories data from GitHub - fetchData("https://api.github.com/users/mindfiredigital/repos", { - headers: { - Authorization: `token ${githubToken}`, - Accept: "application/vnd.github.v3+json", - }, - }) - ]); + // Fetch repositories data from GitHub + fetchData("https://api.github.com/users/mindfiredigital/repos", { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + }), + ]); // Process and write data for current projects - const currentProjects = currentProjectsData.data.foss_projects.map(entry => ({ - ...entry, - id: parseInt(entry.id), - shortDescription: entry.short_description, - githubUrl: entry.github_repository_link, - documentationUrl: entry.documentation_link, - })); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/projects.json"), JSON.stringify(currentProjects, null, 2)); + const currentProjects = currentProjectsData.data.foss_projects.map( + (entry) => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + }) + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/projects.json"), + JSON.stringify(currentProjects, null, 2) + ); console.log("Current projects updated successfully."); // Process and write data for upcoming projects - const upcomingProjects = upcomingProjectsData.data.foss_projects.map(entry => ({ - ...entry, - id: parseInt(entry.id), - shortDescription: entry.short_description, - githubUrl: entry.github_repository_link, - documentationUrl: entry.documentation_link, - })); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/upcomingProjects.json"), JSON.stringify(upcomingProjects, null, 2)); + const upcomingProjects = upcomingProjectsData.data.foss_projects.map( + (entry) => ({ + ...entry, + id: parseInt(entry.id), + shortDescription: entry.short_description, + githubUrl: entry.github_repository_link, + documentationUrl: entry.documentation_link, + }) + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/upcomingProjects.json"), + JSON.stringify(upcomingProjects, null, 2) + ); console.log("Upcoming projects updated successfully."); // Fetch and process contributors data for repositories - const repoNames = repositories.map(repo => repo.name); + const repoNames = repositories.map((repo) => repo.name); const contributorsObject = {}; for (const repoName of repoNames) { - const repoData = await fetchData(`https://api.github.com/repos/mindfiredigital/${repoName}`, { - headers: { - Authorization: `token ${githubToken}`, - Accept: "application/vnd.github.v3+json", - }, - }) - contributorsObject[repoName] = await getCollaborators(repoData, githubToken); + const repoData = await fetchData( + `https://api.github.com/repos/mindfiredigital/${repoName}`, + { + headers: { + Authorization: `token ${githubToken}`, + Accept: "application/vnd.github.v3+json", + }, + } + ); + contributorsObject[repoName] = await getCollaborators( + repoData, + githubToken + ); } // Aggregate contributor from contributors const contributionsMap = {}; for (const repo in contributorsObject) { - contributorsObject[repo].forEach(contributor => { + contributorsObject[repo].forEach((contributor) => { const { login, contributions, id, avatar_url, html_url } = contributor; - contributionsMap[login] = contributionsMap[login] || { id, contributions: 0, html_url, avatar_url, login }; + contributionsMap[login] = contributionsMap[login] || { + id, + contributions: 0, + html_url, + avatar_url, + login, + }; contributionsMap[login].contributions += contributions; }); } // Sort contributions and write data to file - const sortedContributions = Object.values(contributionsMap).sort((a, b) => b.contributions - a.contributions); - fs.writeFileSync(path.join(__dirname, "src/app/projects/assets/contributors.json"), JSON.stringify(sortedContributions, null, 2)); + const sortedContributions = Object.values(contributionsMap).sort( + (a, b) => b.contributions - a.contributions + ); + fs.writeFileSync( + path.join(__dirname, "src/app/projects/assets/contributors.json"), + JSON.stringify(sortedContributions, null, 2) + ); console.log("Contributors list updated successfully."); } catch (error) { console.error("An error occurred:", error); From 3f0dad22d1b7b0f747f071abdf472f7323a1afbe Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Thu, 22 Feb 2024 14:33:37 +0530 Subject: [PATCH 5/7] chore: shift the github icon to left side of login --- src/app/contributors/page.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/contributors/page.tsx b/src/app/contributors/page.tsx index b1e70123..5e824d84 100644 --- a/src/app/contributors/page.tsx +++ b/src/app/contributors/page.tsx @@ -32,13 +32,7 @@ const Contributors = () => { src={contributor.avatar_url} alt={`Contributor ${contributor.login}`} /> -
- {contributor.login} -
-

- Contributions: {contributor.contributions} -

-
+
{ alt='github_img' /> +
+ {contributor.login} +
+

+ Contributions: {contributor.contributions} +

))} From 424e425db3e566701cb2d5a46bc389438de609af Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Fri, 23 Feb 2024 13:11:33 +0530 Subject: [PATCH 6/7] feat: add contributor icon --- public/images/social-media/contributor.svg | 2 + public/images/social-media/git-issue.svg | 13 ++++++ public/images/social-media/pull-request.svg | 2 + src/app/contributors/page.tsx | 49 +++++++++++++++++++-- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 public/images/social-media/contributor.svg create mode 100644 public/images/social-media/git-issue.svg create mode 100644 public/images/social-media/pull-request.svg diff --git a/public/images/social-media/contributor.svg b/public/images/social-media/contributor.svg new file mode 100644 index 00000000..90cd0a61 --- /dev/null +++ b/public/images/social-media/contributor.svg @@ -0,0 +1,2 @@ + +ionicons-v5-d \ No newline at end of file diff --git a/public/images/social-media/git-issue.svg b/public/images/social-media/git-issue.svg new file mode 100644 index 00000000..93e5d468 --- /dev/null +++ b/public/images/social-media/git-issue.svg @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/public/images/social-media/pull-request.svg b/public/images/social-media/pull-request.svg new file mode 100644 index 00000000..d31e0932 --- /dev/null +++ b/public/images/social-media/pull-request.svg @@ -0,0 +1,2 @@ + +ionicons-v5-d \ No newline at end of file diff --git a/src/app/contributors/page.tsx b/src/app/contributors/page.tsx index 5e824d84..c914d84b 100644 --- a/src/app/contributors/page.tsx +++ b/src/app/contributors/page.tsx @@ -3,6 +3,9 @@ import Link from "next/link"; import React from "react"; import github from "../../../public/images/social-media/github.png"; +import contributorImg from "../../../public/images/social-media/contributor.svg"; +import prImg from "../../../public/images/social-media/pull-request.svg"; +import issueImg from "../../../public/images/social-media/git-issue.svg"; import Image from "next/image"; import contributorList from "../projects/assets/contributors.json"; @@ -45,9 +48,49 @@ const Contributors = () => { {contributor.login} -

- Contributions: {contributor.contributions} -

+
+
+
+
+ github_img +
+

+ {contributor.contributions} +

+
+
+
+ github_img +
+

+ {contributor.contributions / 2} +

+
+
+
+ github_img +
+

+ {contributor.contributions / 4} +

+
+
+
))} From 53321745e1b20453d01e3534f2e1d63d96e4c767 Mon Sep 17 00:00:00 2001 From: Ashutosh8215 Date: Fri, 23 Feb 2024 17:41:57 +0530 Subject: [PATCH 7/7] feat: change icon color to red --- public/images/social-media/contributor.svg | 2 +- public/images/social-media/git-issue.svg | 2 +- public/images/social-media/pull-request.svg | 2 +- src/app/contributors/page.tsx | 17 ++++++++++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/public/images/social-media/contributor.svg b/public/images/social-media/contributor.svg index 90cd0a61..1d94ee45 100644 --- a/public/images/social-media/contributor.svg +++ b/public/images/social-media/contributor.svg @@ -1,2 +1,2 @@ -ionicons-v5-d \ No newline at end of file +ionicons-v5-d \ No newline at end of file diff --git a/public/images/social-media/git-issue.svg b/public/images/social-media/git-issue.svg index 93e5d468..cec5454f 100644 --- a/public/images/social-media/git-issue.svg +++ b/public/images/social-media/git-issue.svg @@ -1,7 +1,7 @@ - diff --git a/public/images/social-media/pull-request.svg b/public/images/social-media/pull-request.svg index d31e0932..ed9e4036 100644 --- a/public/images/social-media/pull-request.svg +++ b/public/images/social-media/pull-request.svg @@ -1,2 +1,2 @@ -ionicons-v5-d \ No newline at end of file +ionicons-v5-d \ No newline at end of file diff --git a/src/app/contributors/page.tsx b/src/app/contributors/page.tsx index c914d84b..213c8191 100644 --- a/src/app/contributors/page.tsx +++ b/src/app/contributors/page.tsx @@ -42,6 +42,8 @@ const Contributors = () => { height={20} width={20} alt='github_img' + loading='lazy' + quality={75} />
@@ -56,7 +58,10 @@ const Contributors = () => { src={contributorImg} height={20} width={20} - alt='github_img' + alt='contributor' + loading='lazy' + quality={75} + title='Contributor' />

@@ -69,7 +74,10 @@ const Contributors = () => { src={prImg} height={20} width={20} - alt='github_img' + alt='pull request' + loading='lazy' + quality={75} + title='Pull request' />

@@ -82,7 +90,10 @@ const Contributors = () => { src={issueImg} height={20} width={20} - alt='github_img' + alt='issue' + loading='lazy' + quality={75} + title='Git issue' />