feat: getIssue.ts print json

This commit is contained in:
monoid 2022-04-20 11:14:48 +09:00
parent b890a4073a
commit 41933dbe98

View File

@ -1,5 +1,6 @@
#! /usr/bin/env deno run --allow-net --allow-env #! /usr/bin/env deno run --allow-net --allow-env
import {Issue} from "./githubType.ts"; import {Issue} from "./githubType.ts";
import {parse} from "https://deno.land/std@0.135.0/flags/mod.ts";
/** /**
* get issue from github * get issue from github
@ -25,13 +26,17 @@ export async function getIssues(repo: string, token: string): Promise<Issue[]> {
if (import.meta.main) { if (import.meta.main) {
const arg = Deno.args.length > 0 ? Deno.args[0] : undefined; const args = parse(Deno.args);
const token = arg ?? Deno.env.get("GITHUB_TOKEN"); const token = args.token ?? Deno.env.get("GITHUB_TOKEN");
if(typeof token !== "string"){
console.error("invalid type: token must be string");
Deno.exit(1);
}
if(!token) { if(!token) {
console.error("GITHUB_TOKEN is not set"); console.error("GITHUB_TOKEN is not set");
Deno.exit(1); Deno.exit(1);
} }
const issues = await getIssues("vi117/scrap-yard", token); const issues = await getIssues("vi117/scrap-yard", token);
issues.sort((a, b) => a.number - b.number); issues.sort((a, b) => a.number - b.number);
console.log(issues.map(i => `# (${i.number}) ${i.title}\n${i.body}`).join("\n\n")); console.log(JSON.stringify(issues,undefined,2));
} }