forked from TrustUp-app/TrustUp-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-leaderboard.js
More file actions
59 lines (43 loc) · 1.44 KB
/
Copy pathgenerate-leaderboard.js
File metadata and controls
59 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require('fs');
const REPO = process.env.GITHUB_REPOSITORY;
const TOKEN = process.env.GITHUB_TOKEN;
async function getContributors() {
const res = await fetch(`https://api.github.com/repos/${REPO}/contributors`, {
headers: {
Authorization: `token ${TOKEN}`,
},
});
return await res.json();
}
function generateMarkdown(contributors) {
const excludedUsers = ['D240021', 'Josue19-08'];
const filtered = contributors.filter((c) => !excludedUsers.includes(c.login));
const top = filtered.slice(0, 3);
let md = `## 🏆 Top 3 Contributors\n\n`;
md += `<div align="center">\n\n<table>\n<tr>\n`;
top.forEach((c, index) => {
const medals = ['🥇', '🥈', '🥉'];
md += `
<td align="center">
<a href="${c.html_url}">
<img src="${c.avatar_url}" width="100px;" style="border-radius:50%;" alt="${c.login}"/><br />
<sub><b>${medals[index]} @${c.login}</b></sub><br />
<sub>${c.contributions} contributions</sub>
</a>
</td>
`;
});
md += `\n</tr>\n</table>\n</div>\n`;
return md;
}
async function main() {
const contributors = await getContributors();
const leaderboard = generateMarkdown(contributors);
const readme = fs.readFileSync('README.md', 'utf-8');
const newReadme = readme.replace(
/<!-- LEADERBOARD_START -->[\s\S]*<!-- LEADERBOARD_END -->/,
`<!-- LEADERBOARD_START -->\n${leaderboard}\n<!-- LEADERBOARD_END -->`
);
fs.writeFileSync('README.md', newReadme);
}
main();