Skip to content

Commit c8853d5

Browse files
committed
feat: modify the update-contributors.js to extract contribution to all public repo of frontendmu
1 parent 26365b9 commit c8853d5

File tree

2 files changed

+75
-18
lines changed

2 files changed

+75
-18
lines changed

.github/workflows/update-contributors.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
pull_request_target:
55
types:
66
- closed
7+
repository_dispatch:
8+
types: [trigger-workflow]
79

810
jobs:
911
update-contributors:

packages/frontendmu-data/scripts/update-contributors.js

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,98 @@
11
import fs from "fs";
22
import { execSync } from "child_process";
33

4-
const owner = "Front-End-Coders-Mauritius";
4+
const owner = "frontendmu";
55
const repo = "frontend.mu";
66
const branch = "main"; // Replace with the default branch of your repository
77

88
const contributorsFile = "./data/contributors.json";
99

1010
async function updateContributors() {
1111
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
1418
);
1519

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+
}
2877
});
78+
}
79+
const updatedContributors = Object.entries(contributorsMap).map(([username, contributions]) => ({
80+
username,
81+
contributions
82+
}));
83+
const contributorsData = JSON.stringify(updatedContributors, null, 2);
2984

30-
const updatedContributors = [...new Set(contributors)];
85+
console.log(contributorsData)
3186

3287
if (
3388
JSON.stringify(updatedContributors) !==
3489
JSON.stringify(getExistingContributors())
3590
) {
3691
fs.writeFileSync(
3792
contributorsFile,
38-
JSON.stringify(updatedContributors, null, 2)
93+
contributorsData
3994
);
40-
console.log("Contributors file updated.");
95+
// console.log("Contributors file updated.");
4196

4297
// Configure Git user and email for the commit
4398
execSync('git config user.name "GitHub Action"');

0 commit comments

Comments
 (0)