| @@ -13,7 +13,7 @@ function get(url, accept) { | |||
| "Authorization": authorization, | |||
| }; | |||
| process.stderr.write(Buffer.from("==> GET " + url + "... ", "utf-8")); | |||
| process.stderr.write(Buffer.from("==> GET " + url + "...\n", "utf-8")); | |||
| let req = https.get(url, {headers}, res => { | |||
| let data = ""; | |||
| res.on("data", d => { | |||
| @@ -24,8 +24,6 @@ function get(url, accept) { | |||
| if (res.statusCode != 200) { | |||
| process.stderr.write(Buffer.from("ERR " + res.statusCode + "\n")); | |||
| throw new Error(data); | |||
| } else { | |||
| process.stderr.write(Buffer.from("OK\n")); | |||
| } | |||
| resolve(data); | |||
| @@ -38,8 +36,32 @@ function apiIssueReactions(repo, comment) { | |||
| return `/repos/${repo}/issues/comments/${comment}/reactions`; | |||
| } | |||
| async function handlePage(page, stream) { | |||
| for (let issue of page) { | |||
| let count = 0; | |||
| let people = []; | |||
| for (let reactionPageNum = 1; ; ++reactionPageNum) { | |||
| let reactionPage = JSON.parse(await get( | |||
| `https://api.github.com/repos/${repo}/issues/${issue.number}/reactions?page=${reactionPageNum}`, | |||
| "application/vnd.github.squirrel-girl-preview")); | |||
| if (reactionPage.length == 0) { | |||
| break; | |||
| } | |||
| for (let reaction of reactionPage) { | |||
| if (reaction.content == "+1") { | |||
| count += 1; | |||
| people.push(reaction.user.login); | |||
| } | |||
| } | |||
| } | |||
| stream.write(issue.title.trim() + ";" + count + ";" + people.join(":") + "\n"); | |||
| } | |||
| } | |||
| async function main(repo, stream) { | |||
| let votes = []; | |||
| let promises = []; | |||
| for (let pageNum = 1; ; ++pageNum) { | |||
| let page = JSON.parse(await get( | |||
| `https://api.github.com/repos/${repo}/issues?state=open&page=${pageNum}`, | |||
| @@ -48,28 +70,10 @@ async function main(repo, stream) { | |||
| break; | |||
| } | |||
| for (let issue of page) { | |||
| let count = 0; | |||
| let people = []; | |||
| for (let reactionPageNum = 1; ; ++reactionPageNum) { | |||
| let reactionPage = JSON.parse(await get( | |||
| `https://api.github.com/repos/${repo}/issues/${issue.number}/reactions?page=${reactionPageNum}`, | |||
| "application/vnd.github.squirrel-girl-preview")); | |||
| if (reactionPage.length == 0) { | |||
| break; | |||
| } | |||
| for (let reaction of reactionPage) { | |||
| if (reaction.content == "+1") { | |||
| count += 1; | |||
| people.push(reaction.user.login); | |||
| } | |||
| } | |||
| } | |||
| stream.write(issue.title.trim() + ";" + count + ";" + people.join(":") + "\n"); | |||
| } | |||
| promises.push(handlePage(page, stream)); | |||
| } | |||
| await Promise.all(promises); | |||
| } | |||
| let stream = fs.createWriteStream(outfile); | |||