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

Commit 1929fe3

Browse files
committed
Query PRs as well.
1 parent 7cb8963 commit 1929fe3

2 files changed

Lines changed: 59 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ List **all** GitHub repos a user has contributed to **since the beginning of tim
99
$ github-contribs AurelienLourot
1010
✔ Fetched first day at GitHub: 2015-04-04.
1111
⚠ Be patient. The whole process might take up to an hour... Consider using `--since` and/or `--until`.
12-
✔ Fetched all commits.
13-
34 repo(s) found:
12+
✔ Fetched all commits and PRs.
13+
35 repo(s) found:
1414
AurelienLourot/lsankidb
1515
reframejs/reframe
1616
dracula/gitk

index.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
};
3838

3939
const getContribs = async (user, joinDate, since, until, ora, console) => {
40-
const htmlToRepos = html => {
40+
const commitsHtmlToRepos = html => {
4141
const repos = new Set();
4242

4343
const handler = new htmlparser.DefaultHandler((error, dom) => {});
@@ -70,6 +70,39 @@
7070
return repos;
7171
};
7272

73+
const prsHtmlToRepos = html => {
74+
const repos = new Set();
75+
76+
const handler = new htmlparser.DefaultHandler((error, dom) => {});
77+
const parser = new htmlparser.Parser(handler);
78+
parser.parseComplete(html);
79+
for (let i = 0; i < handler.dom.length; ++i) {
80+
if (handler.dom[i].type == 'tag' && handler.dom[i].name == 'div') {
81+
const div1 = handler.dom[i].children;
82+
for (let j = 0; j < div1.length; ++j) {
83+
if (div1[j].type == 'tag' && div1[j].name == 'div') {
84+
const div2 = div1[j].children;
85+
for (let k = 0; k < div2.length; ++k) {
86+
if (div2[k].type == 'tag' && div2[k].name == 'button') {
87+
const button = div2[k].children;
88+
for (let l = 0; l < button.length; ++l) {
89+
if (button[l].type == 'tag' && button[l].name == 'span') {
90+
const span = button[l].children[0].data.trim();
91+
if (span) {
92+
repos.add(span);
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
}
102+
103+
return repos;
104+
};
105+
73106
let oldestDate = joinDate;
74107
if (since) {
75108
oldestDate = new Date(Math.max(oldestDate, stringToDate(since)));
@@ -93,20 +126,32 @@
93126

94127
return (async () => {
95128
const tooManyRequests = 429;
129+
const fetchOptions = {
130+
retryOn: [tooManyRequests],
131+
retries: 300,
132+
};
96133
const userCommits = await fetch(
97-
`https://github.com/users/${user}/created_commits?from=${currDateStr}&to=${currDateStr}`, {
98-
retryOn: [tooManyRequests],
99-
retries: 300,
100-
},
134+
`https://github.com/users/${user}/created_commits?from=${currDateStr}&to=${currDateStr}`,
135+
fetchOptions
101136
);
102137
const userCommitsHtml = await userCommits.text();
103-
const repos = htmlToRepos(userCommitsHtml);
104-
commitsSpinner.stop(); // temporary stop for logging
105-
for (let repo of repos) {
106-
console.log(`${currDateStr}: ${repo}`);
138+
const userPRs = await fetch(
139+
`https://github.com/users/${user}/created_pull_requests?from=${currDateStr}&to=${currDateStr}`,
140+
fetchOptions
141+
);
142+
const userPRsHtml = await userPRs.text();
143+
const commitsRepos = commitsHtmlToRepos(userCommitsHtml);
144+
const prsRepos = prsHtmlToRepos(userPRsHtml);
145+
progressSpinner.stop(); // temporary stop for logging
146+
for (let repo of commitsRepos) {
147+
console.log(`${currDateStr}: (commits) ${repo}`);
148+
result.add(repo);
149+
}
150+
for (let repo of prsRepos) {
151+
console.log(`${currDateStr}: (PRs) ${repo}`);
107152
result.add(repo);
108153
}
109-
commitsSpinner.start(`Fetching all commits [${++numOfQueriedDays}/${numOfDaysToQuery}]`);
154+
progressSpinner.start(`Fetching all commits and PRs [${++numOfQueriedDays}/${numOfDaysToQuery}]`);
110155
})();
111156
};
112157
})();
@@ -121,9 +166,9 @@
121166
ora(warning).warn();
122167

123168
const result = new Set();
124-
const commitsSpinner = ora('Fetching all commits...').start();
169+
const progressSpinner = ora('Fetching all commits and PRs...').start();
125170
await new promisePool(getContribsOnOneDay, 5).start();
126-
commitsSpinner.succeed('Fetched all commits.');
171+
progressSpinner.succeed('Fetched all commits and PRs.');
127172
return result;
128173
};
129174

0 commit comments

Comments
 (0)