Skip to content

Commit

Permalink
fix: contribution streak regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieweavis committed Mar 3, 2023
1 parent dc51601 commit ecac074
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down

0 comments on commit ecac074

Please sign in to comment.