From 140646cc28a79e79aa149c2d847708176cad135f Mon Sep 17 00:00:00 2001 From: Jerome Hardaway Date: Tue, 7 Jan 2025 13:50:57 -0500 Subject: [PATCH] Refactor contributor type checking to use a type guard function --- src/lib/github.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index c66e10ca..3e4c8937 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -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) { @@ -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: ${