Created
May 30, 2020 02:38
-
-
Save dgp1130/e24c53bd8005992a7569b58ee4698c4f to your computer and use it in GitHub Desktop.
Lists all open bugs in the Angular CLI repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"userName": "<github-username>", | |
"pat": "<personal-access-token-generated-from-github>" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
// GitHub has some pretty aggressive rate limiting. Don't run this too many times | |
// or you may get locked out for over an hour! Include a personal access token | |
// and username in ./data.json to authenticate the request which raises rate limits. | |
const fetch = require('node-fetch'); | |
const data = require('./data.json'); | |
(async () => { | |
const baseUrl = new URL('https://api.github.com/repos/angular/angular-cli/issues'); | |
baseUrl.username = data.userName; | |
baseUrl.searchParams.set('state', 'open'); | |
// Use limit(getIssues(...), 10) to debug without exhasusting rate limits. | |
for await (const issue of getBugsOrUnlabeled(getIssues(getGitHubIssues(baseUrl)))) { | |
console.log(`=HYPERLINK("${issue.html_url}", "#${issue.number}")`); | |
} | |
})().catch((err) => { | |
console.error('Fatal error', err); | |
process.exit(1); | |
}); | |
async function* getBugsOrUnlabeled(issues) { | |
for await (const issue of issues) { | |
const typeLabels = issue.labels.map((label) => label.name) | |
.filter((label) => label.startsWith('type:')); | |
if (typeLabels.length > 1) { | |
yield issue; // Multiple type labels, should triage. | |
continue; | |
} | |
if (typeLabels.length === 0) { | |
yield issue; // No type labels, should triage. | |
continue; | |
} | |
const [ typeLabel ] = typeLabels; | |
if (typeLabel === 'type: bug/fix') { | |
// It's a bug, should triage. | |
yield issue; | |
continue; | |
} | |
// Some other type, do not triage. | |
} | |
} | |
// Does not include PRs | |
async function* getIssues(githubIssues) { | |
for await (const issue of githubIssues) { | |
if (!issue.pull_request) yield issue; | |
} | |
} | |
// Includes PRs | |
async function* getGitHubIssues(baseUrl) { | |
let page = 0; | |
while (true) { | |
const url = new URL(baseUrl.toString()); | |
url.searchParams.set('page', page.toString()); | |
const headers = !data.pat ? {} : { | |
'Authorization': `Basic ${data.pat}`, | |
}; | |
const res = await fetch(url, { headers }); | |
const json = await res.json(); | |
if (json.length === 0) return; | |
for (const issue of json) yield issue; | |
page++; | |
} | |
} | |
async function* take(items, count) { | |
for await (const item of items) { | |
if (count <= 0) return; | |
yield item; | |
count--; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "fixit", | |
"version": "1.0.0", | |
"description": "", | |
"scripts": { | |
"start": "node issues.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"node-fetch": "2.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment