forked from openapi-ts/openapi-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-contributors.js
228 lines (215 loc) · 5.39 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
import fs from "node:fs";
import { URL } from "node:url";
const AVATAR_RE = /property="og:image" content="([^"]+)/;
const TITLE_RE = /<title>[^(<]*\(([^)<]+)/;
const CONTRIBUTORS_JSON = new URL("../data/contributors.json", import.meta.url);
const contributors = JSON.parse(fs.readFileSync(CONTRIBUTORS_JSON, "utf8"));
const ONE_MONTH = 1000 * 60 * 60 * 24 * 7 * 30;
async function fetchUserInfo(username) {
const res = await fetch(`https://github.com/${username}`, {
headers: {
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": "en-US,en;q=0.5",
"cache-control": "no-cache",
connection: "keep-alive",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0",
},
});
if (!res.ok) {
throw new Error(`${res.url} responded with ${res.status}`);
}
const body = await res.text();
const avatarMatch = body.match(AVATAR_RE);
if (!avatarMatch) {
throw new Error(`Could not find avatar for ${username}`);
}
const nameMatch = body.match(TITLE_RE);
let name = username;
if (nameMatch?.[1]) {
name = nameMatch[1];
}
return {
avatar: avatarMatch[1],
name,
};
}
function upsert(list, userData) {
const i = list.findIndex((u) => u.username === userData.username);
if (i >= 0) {
list[i] = userData;
} else {
list.push(userData);
}
}
const OPENAPI_TS_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",
"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",
"davidleger95",
"phk422",
"mzronek",
"raurfang",
"JeanRemiDelteil",
"TzviPM",
"LucaSchwan",
"nzapponi",
"luchsamapparat",
"nmacmunn",
]),
];
export const OPENAPI_FETCH_CONTRIBUTORS = [
...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",
]),
];
export const OPENAPI_REACT_QUERY_CONTRIBUTORS = [...new Set(["drwpow", "kerwanp"])];
async function main() {
const total = [...OPENAPI_TS_CONTRIBUTORS, OPENAPI_FETCH_CONTRIBUTORS, OPENAPI_REACT_QUERY_CONTRIBUTORS].length;
let i = 0;
await Promise.all(
["openapi-typescript", "openapi-fetch", "openapi-react-query"].map(async (repo) => {
const userlist =
repo === "openapi-fetch"
? OPENAPI_FETCH_CONTRIBUTORS
: repo === "openapi-react-query"
? OPENAPI_REACT_QUERY_CONTRIBUTORS
: OPENAPI_TS_CONTRIBUTORS;
for (const username of userlist) {
// skip profiles that have been updated within the past week
const { lastFetch } = contributors[repo].find((u) => u.username === username) ?? { lastFetch: 0 };
if (Date.now() - lastFetch < ONE_MONTH) {
continue;
}
// note: fetch sequentially, otherwise GitHub times out (429)
// also run on every docs build to pick up updated avatars
try {
const userData = {
username,
...(await fetchUserInfo(username)),
links: [{ icon: "github", link: `https://github.com/${username}` }],
lastFetch: new Date().getTime(),
};
upsert(contributors[repo], userData);
i++;
// 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(contributors)); // update file while fetching (sync happens safely in between fetches)
await new Promise((resolve) => setTimeout(resolve, 900)); // sleep to prevent 429
} catch (err) {
throw new Error(err);
}
}
}),
);
}
main();