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

Commit 515469f

Browse files
committed
Fix after GitHub's interface has changed // ghuser-io/ghuser.io#172
1 parent 5facef9 commit 515469f

File tree

4 files changed

+26
-52
lines changed

4 files changed

+26
-52
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Normally in order to retrieve all repositories a user has interacted with, one s
7070
Instead we noticed that the "Contribution Activity" on the
7171
[profile pages](https://github.com/AurelienLourot) queries such URLs in the background:
7272

73-
* https://github.com/users/AurelienLourot/created_commits?from=2018-05-17&to=2018-05-17
7473
* https://github.com/users/AurelienLourot/created_repositories?from=2018-05-17&to=2018-05-17
7574
* https://github.com/users/AurelienLourot/created_pull_request_reviews?from=2018-05-17&to=2018-05-17
7675
* https://github.com/users/AurelienLourot/created_issues?from=2018-07-10&to=2018-07-10
@@ -103,6 +102,13 @@ So we're doing the same :)
103102
> <a href="/tt-gf/ant-ivy/pull/2" class="content-title no-underline">
104103
> ```
105104
105+
> * Same now with `created_commits`:
106+
>
107+
> ```bash
108+
> $ curl -s "https://github.com/AurelienLourot?from=2017-08-27" | grep commits?
109+
> <a href="/AurelienLourot/mybeir.ut/commits?author=AurelienLourot&amp;since=2017-08-27&amp;until=2017-08-28" class="f6 muted-link ml-1">
110+
> ```
111+
106112
### Why is it so slow?
107113
108114
We hit a [rate limit](https://en.wikipedia.org/wiki/Rate_limiting). And since it's not an official
@@ -129,6 +135,10 @@ doesn't discover commits in forks.
129135
130136
## Changelog
131137
138+
**2.2.3** (2018-10-20):
139+
* [ghuser-io/ghuser.io#172](https://github.com/ghuser-io/ghuser.io/issues/172) Fix after GitHub's
140+
interface has changed. The `created_commits` "endpoint" is gone.
141+
132142
**2.2.2** (2018-10-13):
133143
* [ghuser-io/ghuser.io#172](https://github.com/ghuser-io/ghuser.io/issues/172) Fix after GitHub's
134144
interface has changed. The `created_pull_requests` "endpoint" is gone.

index.js

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,6 @@
8383
};
8484

8585
const getContribs = async (user, joinDate, since, until, ora, console, alsoIssues) => {
86-
const commitsHtmlToRepos = html => {
87-
const repos = new Set();
88-
89-
const handler = new htmlparser.DefaultHandler((error, dom) => {});
90-
const parser = new htmlparser.Parser(handler);
91-
parser.parseComplete(html);
92-
for (let i = 0; i < handler.dom.length; ++i) {
93-
if (handler.dom[i].type === 'tag' && handler.dom[i].name === 'ul') {
94-
const ul = handler.dom[i].children;
95-
for (let j = 0; j < ul.length; ++j) {
96-
if (ul[j].type === 'tag' && ul[j].name === 'li') {
97-
const li = ul[j].children;
98-
for (let k = 0; k < li.length; ++k) {
99-
if (li[k].type === 'tag' && li[k].name === 'div') {
100-
const div = li[k].children;
101-
for (let l = 0; l < div.length; ++l) {
102-
if (div[l].type === 'tag' && div[l].name === 'a') {
103-
const a = div[l].children[0].data;
104-
if (!a.includes(' ')) {
105-
repos.add(a);
106-
}
107-
}
108-
}
109-
}
110-
}
111-
}
112-
}
113-
}
114-
}
115-
116-
return repos;
117-
};
118-
11986
const issuesHtmlToRepos = html => {
12087
const repos = new Set();
12188

@@ -149,10 +116,11 @@
149116
return repos;
150117
};
151118

152-
const bigHtmlToRepos = (html, type) => { // type: 'issues' or 'pulls'
119+
const bigHtmlToRepos = (html, type) => { // type: 'issues', 'pull' or 'commits'
153120
const repos = new Set();
154121

155-
const regex = new RegExp(`<a.*href="/(.*)/(.*)/${type}/`, 'g');
122+
const charAfterType = type === 'commits' ? '?' : '/';
123+
const regex = new RegExp(`<a.*href="/(.*)/(.*)/${type}${charAfterType}`, 'g');
156124
let linkToIssue;
157125
while ((linkToIssue = regex.exec(html))) {
158126
const owner = linkToIssue[1];
@@ -204,17 +172,11 @@
204172
currDate = prevDay(currDate);
205173

206174
return (async () => {
207-
const userCommits = await fetchRetry(
208-
`https://github.com/users/${user}/created_commits?from=${currDateStr}&to=${currDateStr}`
209-
);
210-
const userCommitsHtml = await userCommits.text();
211-
const commitsRepos = commitsHtmlToRepos(userCommitsHtml);
212-
213-
const userPRsAndHotIssues = await fetchRetry(
175+
const bigHtml = await (await fetchRetry(
214176
`https://github.com/${user}?from=${currDateStr}`,
215-
);
216-
const userPRsAndHotIssuesHtml = await userPRsAndHotIssues.text();
217-
const prsRepos = bigHtmlToRepos(userPRsAndHotIssuesHtml, 'pull');
177+
)).text();
178+
const commitsRepos = bigHtmlToRepos(bigHtml, 'commits');
179+
const prsRepos = bigHtmlToRepos(bigHtml, 'pull');
218180

219181
let issuesRepos = [];
220182
let hotIssuesRepos = [];
@@ -225,7 +187,7 @@
225187
const userIssuesHtml = await userIssues.text();
226188
issuesRepos = issuesHtmlToRepos(userIssuesHtml);
227189

228-
hotIssuesRepos = bigHtmlToRepos(userPRsAndHotIssuesHtml, 'issues');
190+
hotIssuesRepos = bigHtmlToRepos(bigHtml, 'issues');
229191
}
230192

231193
progressSpinner.stop(); // temporary stop for logging

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ghuser/github-contribs",
3-
"version": "2.2.2",
3+
"version": "2.2.3",
44
"description": "List all GitHub repos a user has contributed to since the beginning of time.",
55
"license": "Unlicense",
66
"repository": {
@@ -73,6 +73,6 @@
7373
".js"
7474
],
7575
"check-coverage": true,
76-
"lines": 75
76+
"lines": 70
7777
}
7878
}

test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ test('fetches commits and PRs', async t => {
3131
const result = await m.fetch('AurelienLourot', '2017-08-26', '2017-08-28', ora, console);
3232

3333
// Because AurelienLourot had no activity on 2017-08-26, GitHub chooses to display older activity
34-
// on his profile, namely a PR for `brandon-rhodes/uncommitted` on 2017-07-08. This is a known
35-
// limitation and we think it's better to discover too much than not enough.
34+
// on his profile, namely a PR for `brandon-rhodes/uncommitted` on 2017-07-08 and some commits to
35+
// `AurelienLourot/myberl.in`. This is a known limitation and we think it's better to discover too
36+
// much than not enough.
3637

37-
t.is(result.size, 3);
38+
t.is(result.size, 4);
3839
t.true(result.has('AurelienLourot/mybeir.ut'));
3940
t.true(result.has('tt-gf/ant-ivy'));
4041
t.true(result.has('brandon-rhodes/uncommitted'));
42+
t.true(result.has('AurelienLourot/myberl.in'));
4143
});
4244

4345
test('fetches issues', async t => {

0 commit comments

Comments
 (0)