Skip to content

Instantly share code, notes, and snippets.

@dgp1130
Created May 30, 2020 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgp1130/e24c53bd8005992a7569b58ee4698c4f to your computer and use it in GitHub Desktop.
Save dgp1130/e24c53bd8005992a7569b58ee4698c4f to your computer and use it in GitHub Desktop.
Lists all open bugs in the Angular CLI repo
{
"userName": "<github-username>",
"pat": "<personal-access-token-generated-from-github>"
}
// @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--;
}
}
{
"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