Skip to content

Commit a2cffdd

Browse files
committed
Skip updating contributors with unavailable GitHub accounts, fixes #1990
1 parent 639ec45 commit a2cffdd

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

docs/scripts/update-contributors.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ if (!GITHUB_TOKEN) {
1414
);
1515
}
1616

17+
class UserFetchError extends Error {
18+
/**
19+
* @param {string} message
20+
* @param {Response} response
21+
*/
22+
constructor(message, response) {
23+
super(message);
24+
this.name = "UserFetchError";
25+
this.response = response;
26+
}
27+
28+
/**
29+
* @returns {boolean}
30+
*/
31+
get notFound() {
32+
return this.response.status === 404;
33+
}
34+
}
35+
1736
async function fetchUserInfo(username) {
1837
const res = await fetch(`https://api.github.com/users/${username}`, {
1938
headers: {
@@ -23,7 +42,7 @@ async function fetchUserInfo(username) {
2342
},
2443
});
2544
if (!res.ok) {
26-
throw new Error(`${res.url} responded with ${res.status}`);
45+
throw new UserFetchError(`${res.url} responded with ${res.status}`, res);
2746
}
2847
return await res.json();
2948
}
@@ -165,7 +184,7 @@ const CONTRIBUTORS = {
165184
"illright",
166185
]),
167186
"openapi-react-query": new Set(["drwpow", "kerwanp", "yoshi2no"]),
168-
"swr-openapi": new Set(["htunnicliff"])
187+
"swr-openapi": new Set(["htunnicliff"]),
169188
};
170189

171190
async function main() {
@@ -175,9 +194,10 @@ async function main() {
175194
Object.entries(CONTRIBUTORS).map(async ([repo, contributors]) => {
176195
data[repo] ??= [];
177196
for (const username of [...contributors]) {
197+
const existing = data[repo].find((u) => u.username === username);
178198
i++;
179199
// skip profiles that have been updated within the past week
180-
const { lastFetch } = data[repo].find((u) => u.username === username) ?? { lastFetch: 0 };
200+
const { lastFetch } = existing ?? { lastFetch: 0 };
181201
if (Date.now() - lastFetch < ONE_WEEK) {
182202
// biome-ignore lint/suspicious/noConsoleLog: this is a script
183203
console.log(`[${i}/${total}] (Skipped ${username})`);
@@ -197,6 +217,11 @@ async function main() {
197217
console.log(`[${i}/${total}] Updated for ${username}`);
198218
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(data)); // update file while fetching (sync happens safely in between fetches)
199219
} catch (err) {
220+
if (err instanceof UserFetchError && err.notFound) {
221+
console.warn(`[${i}/${total}] (Skipped ${username}, not found)`);
222+
continue;
223+
}
224+
200225
throw new Error(err);
201226
}
202227
}

0 commit comments

Comments
 (0)