Skip to content

Commit

Permalink
fix: contribution count regex
Browse files Browse the repository at this point in the history
GitHub changed the markup on the user contribution page causing all
contribution stats to be 0
  • Loading branch information
jamieweavis committed Mar 3, 2023
1 parent ea9a048 commit e40b546
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

9 changes: 4 additions & 5 deletions src/contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const parseBody = (body: string): GitHubStats => {
};

const matches = [];
const regex = /data-count="(.*?)"/g;
const contributionsRegex = /(\d+) contributions on/g;
let found;
while ((found = regex.exec(body))) matches.push(found);
while ((found = contributionsRegex.exec(body))) matches.push(found);

matches.forEach((match) => {
const count = parseInt(match[1], 10);
Expand All @@ -49,6 +49,7 @@ const parseBody = (body: string): GitHubStats => {
streak.current = count > 0 ? (streak.current += 1) : 0;
if (streak.current > streak.best) streak.best = streak.current;
});

return { streak, contributions };
};

Expand All @@ -60,9 +61,7 @@ const fetchStats = (
get(`https://github.com/users/${username}/contributions`, (response) => {
let body = '';
response.setEncoding('utf8');
response.on('data', (chunk) => {
body += chunk;
});
response.on('data', (chunk) => (body += chunk));
response.on('end', () => {
if (response.statusCode === 404) {
if (options.onFailure) return options.onFailure(response);
Expand Down

0 comments on commit e40b546

Please sign in to comment.