-
-
Notifications
You must be signed in to change notification settings - Fork 639
Expand file tree
/
Copy pathupdate-contributors.js
More file actions
295 lines (283 loc) · 6.15 KB
/
update-contributors.js
File metadata and controls
295 lines (283 loc) · 6.15 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import fs from "node:fs";
import { URL } from "node:url";
const MAINTAINERS = {
drwpow: "Lead, Creator openapi-typescript/openapi-fetch",
kerwanp: "Core Contributor, Creator openapi-react-query",
gzm0: "Core Contributor",
duncanbeevers: "Core Contributor",
htunnicliff: "Core Contributor, Creator swr-openapi",
};
// all usernames
const CONTRIBUTORS = 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",
"kerwanp",
"gzm0",
"htunnicliff",
"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",
"phk422",
"JeanRemiDelteil",
"TzviPM",
"LucaSchwan",
"nzapponi",
"luchsamapparat",
"nmacmunn",
"fergusean",
"shinzui",
"ezpuzz",
"KotoriK",
"yoshi2no",
"fletchertyler914",
"nholik",
"nkt",
"CodazziS",
"michalfedyna",
"roj1512",
"IGx89",
"nickcaballero",
"tcztzy",
"yukukotani",
"hd-o",
"zaru",
"kecrily",
"marcomuser",
"HugeLetters",
"Fumaz",
"illright",
"FreeAoi",
"zhu-hong",
"hungify",
"nmacmunn",
"luchsamapparat",
"jaredLunde",
"armandabric",
"fitztrev",
"jonathanmv",
"darwish",
"swatcher",
"Snaylaker",
"avaly",
"Mask-MJ",
"danmichaelo",
"333fred",
"thatsprettyfaroutman",
"kaechele",
"SebastienGllmt",
"morleytatro",
"ngraef",
"valerijmedvid",
"brunolca",
"Gruak",
"mikestopcontinues",
"JE-Lee",
"vipentti",
"armandabric",
"goce-cz",
"BradHacker",
"crutch12",
"HHongSeungWoo",
"yicrotkd",
"makotot",
"tommy-ish",
"BlakeSzabo",
"ElayGelbart",
"piousdeer",
"DjordyKoert",
"zsugabubus",
"jo-m",
"prewk",
"HugeLetters",
"sultaniman",
"luchsamapparat",
"patzick",
"mellster2012",
"mochi-sann",
"laurenz-glueck",
"gduliscouet-ubitransport",
"alikehel",
"chailandau",
"bennobuilder",
"HagenMorano",
"jungwoo3490",
"freshgiammi",
"lukasedw",
"ViktorPontinen",
"kevmo314",
"arnaud9145",
]);
const ONE_WEEK = 1000 * 60 * 60 * 24;
const CONTRIBUTORS_JSON = new URL("../data/contributors.json", import.meta.url);
const data = JSON.parse(fs.readFileSync(CONTRIBUTORS_JSON, "utf8"));
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);
}
}
async function main() {
let i = 0;
// note: this is sequential, but the GitHub API is fast. It won’t always allow
// too many simultaneous requests, and a queue is overkill for this amount of data.
for (const username of CONTRIBUTORS) {
const group = username in MAINTAINERS ? "maintainers" : "contributors";
i++;
// skip profiles that have been updated within the past week
const { lastFetch } = data[group]?.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}/${CONTRIBUTORS.size}] (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}` }],
title: MAINTAINERS[username] ?? "Contributor",
lastFetch: new Date().getTime(),
};
upsert(data[group], userData);
// biome-ignore lint/suspicious/noConsoleLog: this is a script
console.log(`[${i}/${CONTRIBUTORS.size}] 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();