Skip to content

Commit

Permalink
Refactor contributor type checking to use a type guard function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromehardaway committed Jan 7, 2025
1 parent 2ec79d6 commit 140646c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const octokit = new Octokit({
retry: { enabled: true },
});

function isVWCContributor(c: any): c is VWCContributor {
return c !== null && "login" in c && "name" in c;
}

async function rateLimit() {
const { data } = await octokit.rest.rateLimit.get();
if (data.rate.remaining < 10) {
Expand Down Expand Up @@ -52,7 +56,7 @@ export async function getProjectContributors(
})
);

return contributorsWithDetails.filter((c): c is VWCContributor => c !== null);
return contributorsWithDetails.filter(isVWCContributor);
} catch (error) {
throw new Error(
`Failed to fetch project contributors: ${
Expand Down

0 comments on commit 140646c

Please sign in to comment.