Skip to content

Instantly share code, notes, and snippets.

@nojvek
Created September 21, 2021 20:18
Show Gist options
  • Save nojvek/5fa84c0a7fcb5da29243e8fb433d6b7a to your computer and use it in GitHub Desktop.
Save nojvek/5fa84c0a7fcb5da29243e8fb433d6b7a to your computer and use it in GitHub Desktop.
const fs = require('fs');
const fetch = require('node-fetch');
const GH_TOKEN = process.env.GH_TOKEN;
const repo = 'recurrency/frontend';
if (!GH_TOKEN) {
console.error(`need env var GH_TOKEN`);
console.log(process.env);
process.exit(1);
}
async function main() {
const gql = `
{
repository(owner: "recurrency", name: "frontend") {
issues(first: 100, filterBy: {states: OPEN}, after: "Y3Vyc29yOnYyOpHOOfvgoA==") {
nodes {
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
`;
const response = await (
await fetch(`https://api.github.com/graphql`, {
method: 'POST',
headers: { Authorization: `bearer ${GH_TOKEN}` },
body: JSON.stringify({ query: gql }),
})
).json();
if (response.errors) {
throw new Error(`${response.errors[0].type}: ${response.errors[0].message}`);
}
const issues = response.data.repository.issues;
const issuesTsv = issues.nodes.map((issue) => `${issue.number}\t${issue.title}`).join(`\n`);
fs.writeFileSync('scripts/issues.tsv', issuesTsv, 'utf8');
console.log(issues.pageInfo);
}
main().catch((err) => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment