-
-
Notifications
You must be signed in to change notification settings - Fork 528
/
Copy pathupdate-contributors.js
234 lines (222 loc) · 5.44 KB
/
update-contributors.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import fs from "node:fs";
import { URL } from "node:url";
const CONTRIBUTORS_JSON = new URL("../data/contributors.json", import.meta.url);
const data = JSON.parse(fs.readFileSync(CONTRIBUTORS_JSON, "utf8"));
const ONE_WEEK = 1000 * 60 * 60 * 24;
function getGitHubToken() {
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
if (!GITHUB_TOKEN) {
throw new Error(
'GITHUB_TOKEN not set! Create a token with "read:user" scope and set as an environment variable.\nhttps://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic',
);
}
return GITHUB_TOKEN;
}
class UserFetchError extends Error {
/**
* @param {string} message
* @param {Response} response
*/
constructor(message, response) {
super(message);
this.name = "UserFetchError";
this.response = response;
}
/**
* @returns {boolean}
*/
get notFound() {
return this.response.status === 404;
}
}
async function fetchUserInfo(username) {
const res = await fetch(`https://api.github.com/users/${username}`, {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${getGitHubToken()}`,
"X-GitHub-Api-Version": "2022-11-28",
},
});
if (!res.ok) {
throw new UserFetchError(`${res.url} responded with ${res.status}`, res);
}
return await res.json();
}
function upsert(list, userData) {
const i = list.findIndex((u) => u.username === userData.username);
if (i >= 0) {
list[i] = userData;
} else {
list.push(userData);
}
}
const CONTRIBUTORS = {
"openapi-typescript": new Set([
"drwpow",
"psmyrdek",
"enmand",
"atlefren",
"tpdewolf",
"tombarton",
"svnv",
"sorin-davidoi",
"scvnathan",
"lbenie",
"bokub",
"antonk52",
"tshelburne",
"typeofweb",
"skh-",
"BlooJeans",
"selbekk",
"Mause",
"henhal",
"gr2m",
"samdbmg",
"rendall",
"robertmassaioli",
"jankuca",
"th-m",
"asithade",
"misha-erm",
"radist2s",
"FedeBev",
"yamacent",
"dnalborczyk",
"FabioWanner",
"ashsmith",
"mehalter",
"Chrg1001",
"sharmarajdaksh",
"shuluster",
"FDiskas",
"ericzorn93",
"mbelsky",
"techbech",
"rustyconover",
"bunkscene",
"ottomated",
"sadfsdfdsa",
"ajaishankar",
"dominikdosoudil",
"kgtkr",
"berzi",
"PhilipTrauner",
"Powell-v2",
"duncanbeevers",
"tkukushkin",
"Semigradsky",
"MrLeebo",
"axelhzf",
"imagoiq",
"BTMPL",
"HiiiiD",
"yacinehmito",
"sajadtorkamani",
"mvdbeek",
"sgrimm",
"Swiftwork",
"mtth",
"mitchell-merry",
"qnp",
"shoffmeister",
"liangskyli",
"happycollision",
"ysmood",
"barakalon",
"horaklukas",
"pvanagtmaal",
"toomuchdesign",
"psychedelicious",
"tkrotoff",
"pimveldhuisen",
"asvishnyakov",
"SchabaJo",
"AhsanFazal",
"ElForastero",
"msgadi",
"muttonchop",
"christoph-fricke",
"JorrinKievit",
"WickyNilliams",
"hrsh7th",
"phk422",
"mzronek",
"raurfang",
"JeanRemiDelteil",
"TzviPM",
"LucaSchwan",
"nzapponi",
"luchsamapparat",
"nmacmunn",
]),
"openapi-fetch": new Set([
"drwpow",
"fergusean",
"shinzui",
"ezpuzz",
"KotoriK",
"fletchertyler914",
"nholik",
"roj1512",
"nickcaballero",
"hd-o",
"kecrily",
"psychedelicious",
"muttonchop",
"marcomuser",
"HugeLetters",
"Fumaz",
"darwish",
"kaechele",
"phk422",
"mikestopcontinues",
"JE-Lee",
"vipentti",
"armandabric",
"illright",
]),
"openapi-react-query": new Set(["drwpow", "kerwanp", "yoshi2no", "HugeLetters"]),
"swr-openapi": new Set(["htunnicliff"]),
"openapi-metadata": new Set(["kerwanp", "drwpow"]),
};
async function main() {
let i = 0;
const total = Object.values(CONTRIBUTORS).reduce((total, next) => total + next.size, 0);
await Promise.all(
Object.entries(CONTRIBUTORS).map(async ([repo, contributors]) => {
data[repo] ??= [];
for (const username of [...contributors]) {
i++;
// skip profiles that have been updated within the past week
const { lastFetch } = data[repo].find((u) => u.username === username) ?? { lastFetch: 0 };
if (Date.now() - lastFetch < ONE_WEEK) {
// biome-ignore lint/suspicious/noConsoleLog: this is a script
console.log(`[${i}/${total}] (Skipped ${username})`);
continue;
}
try {
const { avatar_url: avatar, name } = await fetchUserInfo(username);
const userData = {
username,
name,
avatar,
links: [{ icon: "github", link: `https://github.com/${username}` }],
lastFetch: new Date().getTime(),
};
upsert(data[repo], userData);
// biome-ignore lint/suspicious/noConsoleLog: this is a script
console.log(`[${i}/${total}] Updated for ${username}`);
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(data)); // update file while fetching (sync happens safely in between fetches)
} catch (err) {
if (err instanceof UserFetchError && err.notFound) {
console.warn(`[${i}/${total}] (Skipped ${username}, not found)`);
continue;
}
throw new Error(err);
}
}
}),
);
}
main();