From ecac074d03c8600367e39e0ab00e0b6540a1fe61 Mon Sep 17 00:00:00 2001 From: Jamie Weavis Date: Fri, 3 Mar 2023 09:50:42 +0000 Subject: [PATCH] fix: contribution streak regex --- src/contribution.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/contribution.ts b/src/contribution.ts index ea69507..89e410e 100644 --- a/src/contribution.ts +++ b/src/contribution.ts @@ -34,19 +34,22 @@ const parseBody = (body: string): GitHubStats => { current: 0, }; - const matches = []; - const contributionsRegex = /(\d+) contributions on/g; - let found; - while ((found = contributionsRegex.exec(body))) matches.push(found); + const contributionMatches = []; + const contributionRegex = /(\d+|No) contributions on/g; + let contributionMatch; + while ((contributionMatch = contributionRegex.exec(body))) + contributionMatches.push(contributionMatch); - matches.forEach((match) => { - const count = parseInt(match[1], 10); + contributionMatches.forEach((contributionMatch) => { + let contributionCount = + contributionMatch[1] === 'No' ? 0 : parseInt(contributionMatch[1], 10); - contributions.total += count; - contributions.current = count; - if (count > contributions.best) contributions.best = count; + contributions.total += contributionCount; + contributions.current = contributionCount; + if (contributionCount > contributions.best) + contributions.best = contributionCount; - streak.current = count > 0 ? (streak.current += 1) : 0; + streak.current = contributionCount > 0 ? (streak.current += 1) : 0; if (streak.current > streak.best) streak.best = streak.current; });