Skip to content

Commit 9971e7b

Browse files
authored
Skip updating contributors with unavailable GitHub accounts, fixes #1990 (#1991)
1 parent 639ec45 commit 9971e7b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/scripts/update-contributors.js

+26-2
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() {
@@ -197,6 +216,11 @@ async function main() {
197216
console.log(`[${i}/${total}] Updated for ${username}`);
198217
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(data)); // update file while fetching (sync happens safely in between fetches)
199218
} catch (err) {
219+
if (err instanceof UserFetchError && err.notFound) {
220+
console.warn(`[${i}/${total}] (Skipped ${username}, not found)`);
221+
continue;
222+
}
223+
200224
throw new Error(err);
201225
}
202226
}

0 commit comments

Comments
 (0)