Skip to content

Commit

Permalink
feat: update the update-contributor script to use the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
derecklhw committed Oct 22, 2024
1 parent 209f2ce commit 69efa77
Showing 1 changed file with 10 additions and 42 deletions.
52 changes: 10 additions & 42 deletions packages/frontendmu-data/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import fs from "fs";
import { execSync } from "child_process";

const owner = "frontendmu";
const repo = "frontend.mu";
const branch = "main"; // Replace with the default branch of your repository

const contributorsFile = "./data/contributors.json";
const configSource = `https://raw.githubusercontent.com/${owner}/frontend.mu/${branch}/packages/frontendmu-data/scripts/update-contributors.config.json`

async function updateContributors() {
try {
const config = await loadConfig();
const includedRepositories = config.includedRepositories;
const excludedContributors = config.excludedContributors;

const allPublicRepositoriesList = await fetch(
`https://api.github.com/users/${owner}/repos`
).then((response) => response.json());
Expand All @@ -17,55 +21,16 @@ async function updateContributors() {
(repo) => repo.name
);

// console.log("All public repositories:", allPublicRepositories);
// [
// '.github',
// 'branding',
// 'conference-2024',
// 'events',
// 'frontend.mu',
// 'frontendmu-daisy',
// 'frontendmu-nuxt',
// 'frontendmu-ticket',
// 'google-photos-sync',
// 'hacktoberfestmu-2019',
// 'meetupFEC',
// 'nuxt-workshop-devcon2024',
// 'nuxt-workshop-devcon2024-preparations',
// 'playground',
// 'vercel-og-next',
// 'video'
// ]

// const contributors = [];
const contributorsMap = {};

const excludedContributors = ["actions-user", "github-actions[bot]"];
const excludedRepositories = [".github", "google-photos-sync", "branding"];

for (const repo of allPublicRepositories) {
if (excludedRepositories.includes(repo)) {
if (!includedRepositories.includes(repo)) {
continue;
}
const contributorsList = await fetch(
`https://api.github.com/repos/${owner}/${repo}/contributors`
).then((response) => response.json());

// const contributorsListFiltered = contributorsList
// .map((contributor) => {
// return {
// username: contributor.login,
// contributions: contributor.contributions,
// };
// })
// .filter((contributor) => {
// return !excludedContributors.includes(contributor.username);
// });
// contributors.push(...contributorsListFiltered);
// console.log(`Contributors for ${repo}:`, contributorsListFiltered);
// }
// const updatedContributors = [...new Set(contributors)];

contributorsList.forEach((contributor) => {
if (!excludedContributors.includes(contributor.login)) {
if (contributorsMap[contributor.login]) {
Expand All @@ -92,7 +57,6 @@ async function updateContributors() {
contributorsFile,
contributorsData
);
// console.log("Contributors file updated.");

// Configure Git user and email for the commit
execSync('git config user.name "GitHub Action"');
Expand Down Expand Up @@ -125,4 +89,8 @@ function getExistingContributors() {
return [];
}

async function loadConfig() {
return await fetch(configSource).then((response) => response.json());
}

updateContributors();

0 comments on commit 69efa77

Please sign in to comment.