|
1 | 1 | import fs from "fs";
|
2 | 2 | import { execSync } from "child_process";
|
3 | 3 |
|
4 |
| -const owner = "Front-End-Coders-Mauritius"; |
| 4 | +const owner = "frontendmu"; |
5 | 5 | const repo = "frontend.mu";
|
6 | 6 | const branch = "main"; // Replace with the default branch of your repository
|
7 | 7 |
|
8 | 8 | const contributorsFile = "./data/contributors.json";
|
9 | 9 |
|
10 | 10 | async function updateContributors() {
|
11 | 11 | try {
|
12 |
| - const response = await fetch( |
13 |
| - `https://api.github.com/repos/${owner}/${repo}/contributors` |
| 12 | + const allPublicRepositoriesList = await fetch( |
| 13 | + `https://api.github.com/users/${owner}/repos` |
| 14 | + ).then((response) => response.json()); |
| 15 | + |
| 16 | + const allPublicRepositories = allPublicRepositoriesList.map( |
| 17 | + (repo) => repo.name |
14 | 18 | );
|
15 | 19 |
|
16 |
| - const result = await response.json(); |
17 |
| - const contributors = result |
18 |
| - .map((contributor) => { |
19 |
| - return { |
20 |
| - username: contributor.login, |
21 |
| - contributions: contributor.contributions, |
22 |
| - }; |
23 |
| - }) |
24 |
| - .filter((contributor) => { |
25 |
| - // Exclude the following contributors from the list |
26 |
| - const excludedContributors = ["actions-user", "github-actions[bot]"]; |
27 |
| - return !excludedContributors.includes(contributor.username); |
| 20 | + // console.log("All public repositories:", allPublicRepositories); |
| 21 | + // [ |
| 22 | + // '.github', |
| 23 | + // 'branding', |
| 24 | + // 'conference-2024', |
| 25 | + // 'events', |
| 26 | + // 'frontend.mu', |
| 27 | + // 'frontendmu-daisy', |
| 28 | + // 'frontendmu-nuxt', |
| 29 | + // 'frontendmu-ticket', |
| 30 | + // 'google-photos-sync', |
| 31 | + // 'hacktoberfestmu-2019', |
| 32 | + // 'meetupFEC', |
| 33 | + // 'nuxt-workshop-devcon2024', |
| 34 | + // 'nuxt-workshop-devcon2024-preparations', |
| 35 | + // 'playground', |
| 36 | + // 'vercel-og-next', |
| 37 | + // 'video' |
| 38 | + // ] |
| 39 | + |
| 40 | + // const contributors = []; |
| 41 | + const contributorsMap = {}; |
| 42 | + |
| 43 | + const excludedContributors = ["actions-user", "github-actions[bot]"]; |
| 44 | + const excludedRepositories = [".github", "google-photos-sync", "branding"]; |
| 45 | + |
| 46 | + for (const repo of allPublicRepositories) { |
| 47 | + if (excludedRepositories.includes(repo)) { |
| 48 | + continue; |
| 49 | + } |
| 50 | + const contributorsList = await fetch( |
| 51 | + `https://api.github.com/repos/${owner}/${repo}/contributors` |
| 52 | + ).then((response) => response.json()); |
| 53 | + |
| 54 | + // const contributorsListFiltered = contributorsList |
| 55 | + // .map((contributor) => { |
| 56 | + // return { |
| 57 | + // username: contributor.login, |
| 58 | + // contributions: contributor.contributions, |
| 59 | + // }; |
| 60 | + // }) |
| 61 | + // .filter((contributor) => { |
| 62 | + // return !excludedContributors.includes(contributor.username); |
| 63 | + // }); |
| 64 | + // contributors.push(...contributorsListFiltered); |
| 65 | + // console.log(`Contributors for ${repo}:`, contributorsListFiltered); |
| 66 | + // } |
| 67 | + // const updatedContributors = [...new Set(contributors)]; |
| 68 | + |
| 69 | + contributorsList.forEach((contributor) => { |
| 70 | + if (!excludedContributors.includes(contributor.login)) { |
| 71 | + if (contributorsMap[contributor.login]) { |
| 72 | + contributorsMap[contributor.login] += contributor.contributions; |
| 73 | + } else { |
| 74 | + contributorsMap[contributor.login] = contributor.contributions; |
| 75 | + } |
| 76 | + } |
28 | 77 | });
|
| 78 | + } |
| 79 | + const updatedContributors = Object.entries(contributorsMap).map(([username, contributions]) => ({ |
| 80 | + username, |
| 81 | + contributions |
| 82 | + })); |
| 83 | + const contributorsData = JSON.stringify(updatedContributors, null, 2); |
29 | 84 |
|
30 |
| - const updatedContributors = [...new Set(contributors)]; |
| 85 | + console.log(contributorsData) |
31 | 86 |
|
32 | 87 | if (
|
33 | 88 | JSON.stringify(updatedContributors) !==
|
34 | 89 | JSON.stringify(getExistingContributors())
|
35 | 90 | ) {
|
36 | 91 | fs.writeFileSync(
|
37 | 92 | contributorsFile,
|
38 |
| - JSON.stringify(updatedContributors, null, 2) |
| 93 | + contributorsData |
39 | 94 | );
|
40 |
| - console.log("Contributors file updated."); |
| 95 | + // console.log("Contributors file updated."); |
41 | 96 |
|
42 | 97 | // Configure Git user and email for the commit
|
43 | 98 | execSync('git config user.name "GitHub Action"');
|
|
0 commit comments