SRS/tools/getIssue.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-04-19 18:26:47 +09:00
#! /usr/bin/env deno run --allow-net --allow-env
type Issue = {
id: number;
url: string;
title: string;
body: string;
2022-04-19 18:30:41 +09:00
number: number,
2022-04-19 18:26:47 +09:00
labels: {
name: string;
}[]
}
/**
* get issue from github
* @param repo repository name with owner (e.g. denoland/deno)
* @param token your github token
* @returns up to 100 issue objects
* @example
* ```ts
* const issues = await getIssues('denoland/deno', 'your-token')
* console.log(issues);
* ```
*/
async function getIssues(repo: string, token: string): Promise<Issue[]> {
const res = await fetch(`https://api.github.com/repos/${repo}/issues?per_page=100`, {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Token ${token}`
}
});
return await res.json();
}
if (import.meta.main) {
const arg = Deno.args.length > 0 ? Deno.args[0] : undefined;
const token = arg ?? Deno.env.get("GITHUB_TOKEN");
if(!token) {
console.error("GITHUB_TOKEN is not set");
Deno.exit(1);
}
const issues = await getIssues("vi117/scrap-yard", token);
2022-04-19 18:30:41 +09:00
issues.sort((a, b) => a.number - b.number);
console.log(issues.map(i => `# (${i.number}) ${i.title}\n${i.body}`).join("\n\n"));
2022-04-19 18:26:47 +09:00
}