-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathgenerateLeaderboard.js
More file actions
130 lines (102 loc) · 2.87 KB
/
Copy pathgenerateLeaderboard.js
File metadata and controls
130 lines (102 loc) · 2.87 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
module.exports = async ({ github, context }) => {
const owner = context.repo.owner;
const repo = context.repo.repo;
const EXCLUDED = new Set([
'shantkhatri',
'harxhit',
'blankirigaya'
]);
const contributors = new Map();
const ensure = (login, avatarUrl, profileUrl) => {
if (!contributors.has(login)) {
contributors.set(login, {
login,
avatarUrl,
profileUrl,
mergedPrs: 0,
openPrs: 0,
issues: 0
});
}
return contributors.get(login);
};
const mergedPrs = await github.paginate(
github.rest.pulls.list,
{
owner,
repo,
state: 'closed',
per_page: 100
}
);
for (const pr of mergedPrs) {
if (!pr.merged_at || !pr.user) continue;
const login = pr.user.login;
if (EXCLUDED.has(login.toLowerCase())) continue;
const user = ensure(
login,
pr.user.avatar_url,
pr.user.html_url
);
user.mergedPrs++;
}
const openPrs = await github.paginate(
github.rest.pulls.list,
{
owner,
repo,
state: 'open',
per_page: 100
}
);
for (const pr of openPrs) {
if (!pr.user) continue;
const login = pr.user.login;
if (EXCLUDED.has(login.toLowerCase())) continue;
const user = ensure(
login,
pr.user.avatar_url,
pr.user.html_url
);
user.openPrs++;
}
const issues = await github.paginate(
github.rest.issues.listForRepo,
{
owner,
repo,
state: 'all',
per_page: 100
}
);
for (const issue of issues) {
if (issue.pull_request || !issue.user) continue;
const login = issue.user.login;
if (EXCLUDED.has(login.toLowerCase())) continue;
const user = ensure(
login,
issue.user.avatar_url,
issue.user.html_url
);
user.issues++;
}
const leaderboard = [...contributors.values()].sort(
(a, b) =>
b.mergedPrs - a.mergedPrs ||
b.issues - a.issues ||
b.openPrs - a.openPrs ||
a.login.localeCompare(b.login)
);
const fs = require('fs');
const path = require('path');
const outputDir = path.join('apps', 'web', 'public');
const outputFile = path.join(outputDir, 'leaderboard.json');
fs.mkdirSync(outputDir, { recursive: true });
fs.writeFileSync(
outputFile,
JSON.stringify(leaderboard, null, 2),
'utf8'
);
console.log(`Generated ${leaderboard.length} contributors`);
console.log(`Leaderboard written to ${outputFile}`);
};