Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

Commit

Permalink
Query PRs as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
lourot committed May 29, 2018
1 parent 7cb8963 commit 1929fe3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ List **all** GitHub repos a user has contributed to **since the beginning of tim
$ github-contribs AurelienLourot
✔ Fetched first day at GitHub: 2015-04-04.
⚠ Be patient. The whole process might take up to an hour... Consider using `--since` and/or `--until`.
✔ Fetched all commits.
34 repo(s) found:
✔ Fetched all commits and PRs.
35 repo(s) found:
AurelienLourot/lsankidb
reframejs/reframe
dracula/gitk
Expand Down
69 changes: 57 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
};

const getContribs = async (user, joinDate, since, until, ora, console) => {
const htmlToRepos = html => {
const commitsHtmlToRepos = html => {
const repos = new Set();

const handler = new htmlparser.DefaultHandler((error, dom) => {});
Expand Down Expand Up @@ -70,6 +70,39 @@
return repos;
};

const prsHtmlToRepos = html => {
const repos = new Set();

const handler = new htmlparser.DefaultHandler((error, dom) => {});
const parser = new htmlparser.Parser(handler);
parser.parseComplete(html);
for (let i = 0; i < handler.dom.length; ++i) {
if (handler.dom[i].type == 'tag' && handler.dom[i].name == 'div') {
const div1 = handler.dom[i].children;
for (let j = 0; j < div1.length; ++j) {
if (div1[j].type == 'tag' && div1[j].name == 'div') {
const div2 = div1[j].children;
for (let k = 0; k < div2.length; ++k) {
if (div2[k].type == 'tag' && div2[k].name == 'button') {
const button = div2[k].children;
for (let l = 0; l < button.length; ++l) {
if (button[l].type == 'tag' && button[l].name == 'span') {
const span = button[l].children[0].data.trim();
if (span) {
repos.add(span);
}
}
}
}
}
}
}
}
}

return repos;
};

let oldestDate = joinDate;
if (since) {
oldestDate = new Date(Math.max(oldestDate, stringToDate(since)));
Expand All @@ -93,20 +126,32 @@

return (async () => {
const tooManyRequests = 429;
const fetchOptions = {
retryOn: [tooManyRequests],
retries: 300,
};
const userCommits = await fetch(
`https://github.com/users/${user}/created_commits?from=${currDateStr}&to=${currDateStr}`, {
retryOn: [tooManyRequests],
retries: 300,
},
`https://github.com/users/${user}/created_commits?from=${currDateStr}&to=${currDateStr}`,
fetchOptions
);
const userCommitsHtml = await userCommits.text();
const repos = htmlToRepos(userCommitsHtml);
commitsSpinner.stop(); // temporary stop for logging
for (let repo of repos) {
console.log(`${currDateStr}: ${repo}`);
const userPRs = await fetch(
`https://github.com/users/${user}/created_pull_requests?from=${currDateStr}&to=${currDateStr}`,
fetchOptions
);
const userPRsHtml = await userPRs.text();
const commitsRepos = commitsHtmlToRepos(userCommitsHtml);
const prsRepos = prsHtmlToRepos(userPRsHtml);
progressSpinner.stop(); // temporary stop for logging
for (let repo of commitsRepos) {
console.log(`${currDateStr}: (commits) ${repo}`);
result.add(repo);
}
for (let repo of prsRepos) {
console.log(`${currDateStr}: (PRs) ${repo}`);
result.add(repo);
}
commitsSpinner.start(`Fetching all commits [${++numOfQueriedDays}/${numOfDaysToQuery}]`);
progressSpinner.start(`Fetching all commits and PRs [${++numOfQueriedDays}/${numOfDaysToQuery}]`);
})();
};
})();
Expand All @@ -121,9 +166,9 @@
ora(warning).warn();

const result = new Set();
const commitsSpinner = ora('Fetching all commits...').start();
const progressSpinner = ora('Fetching all commits and PRs...').start();
await new promisePool(getContribsOnOneDay, 5).start();
commitsSpinner.succeed('Fetched all commits.');
progressSpinner.succeed('Fetched all commits and PRs.');
return result;
};

Expand Down

0 comments on commit 1929fe3

Please sign in to comment.