|
37 | 37 | }; |
38 | 38 |
|
39 | 39 | const getContribs = async (user, joinDate, since, until, ora, console) => { |
40 | | - const htmlToRepos = html => { |
| 40 | + const commitsHtmlToRepos = html => { |
41 | 41 | const repos = new Set(); |
42 | 42 |
|
43 | 43 | const handler = new htmlparser.DefaultHandler((error, dom) => {}); |
|
70 | 70 | return repos; |
71 | 71 | }; |
72 | 72 |
|
| 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 | + |
73 | 106 | let oldestDate = joinDate; |
74 | 107 | if (since) { |
75 | 108 | oldestDate = new Date(Math.max(oldestDate, stringToDate(since))); |
|
93 | 126 |
|
94 | 127 | return (async () => { |
95 | 128 | const tooManyRequests = 429; |
| 129 | + const fetchOptions = { |
| 130 | + retryOn: [tooManyRequests], |
| 131 | + retries: 300, |
| 132 | + }; |
96 | 133 | 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 |
101 | 136 | ); |
102 | 137 | 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}`); |
107 | 152 | result.add(repo); |
108 | 153 | } |
109 | | - commitsSpinner.start(`Fetching all commits [${++numOfQueriedDays}/${numOfDaysToQuery}]`); |
| 154 | + progressSpinner.start(`Fetching all commits and PRs [${++numOfQueriedDays}/${numOfDaysToQuery}]`); |
110 | 155 | })(); |
111 | 156 | }; |
112 | 157 | })(); |
|
121 | 166 | ora(warning).warn(); |
122 | 167 |
|
123 | 168 | const result = new Set(); |
124 | | - const commitsSpinner = ora('Fetching all commits...').start(); |
| 169 | + const progressSpinner = ora('Fetching all commits and PRs...').start(); |
125 | 170 | await new promisePool(getContribsOnOneDay, 5).start(); |
126 | | - commitsSpinner.succeed('Fetched all commits.'); |
| 171 | + progressSpinner.succeed('Fetched all commits and PRs.'); |
127 | 172 | return result; |
128 | 173 | }; |
129 | 174 |
|
|
0 commit comments