| "Authorization": authorization, | "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 req = https.get(url, {headers}, res => { | ||||
| let data = ""; | let data = ""; | ||||
| res.on("data", d => { | res.on("data", d => { | ||||
| if (res.statusCode != 200) { | if (res.statusCode != 200) { | ||||
| process.stderr.write(Buffer.from("ERR " + res.statusCode + "\n")); | process.stderr.write(Buffer.from("ERR " + res.statusCode + "\n")); | ||||
| throw new Error(data); | throw new Error(data); | ||||
| } else { | |||||
| process.stderr.write(Buffer.from("OK\n")); | |||||
| } | } | ||||
| resolve(data); | resolve(data); | ||||
| return `/repos/${repo}/issues/comments/${comment}/reactions`; | 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) { | async function main(repo, stream) { | ||||
| let votes = []; | |||||
| let promises = []; | |||||
| for (let pageNum = 1; ; ++pageNum) { | for (let pageNum = 1; ; ++pageNum) { | ||||
| let page = JSON.parse(await get( | let page = JSON.parse(await get( | ||||
| `https://api.github.com/repos/${repo}/issues?state=open&page=${pageNum}`, | `https://api.github.com/repos/${repo}/issues?state=open&page=${pageNum}`, | ||||
| break; | 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); | let stream = fs.createWriteStream(outfile); |