Skip to content

Skip updating contributors with unavailable GitHub accounts #1991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions docs/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ if (!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: {
Expand All @@ -23,7 +42,7 @@ async function fetchUserInfo(username) {
},
});
if (!res.ok) {
throw new Error(`${res.url} responded with ${res.status}`);
throw new UserFetchError(`${res.url} responded with ${res.status}`, res);
}
return await res.json();
}
Expand Down Expand Up @@ -165,7 +184,7 @@ const CONTRIBUTORS = {
"illright",
]),
"openapi-react-query": new Set(["drwpow", "kerwanp", "yoshi2no"]),
"swr-openapi": new Set(["htunnicliff"])
"swr-openapi": new Set(["htunnicliff"]),
};

async function main() {
Expand Down Expand Up @@ -197,6 +216,11 @@ async function main() {
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);
}
}
Expand Down