From 0fc729490535d9adc104b6498b5af2b8576f2d0c Mon Sep 17 00:00:00 2001 From: monoid Date: Sat, 11 Jun 2022 18:58:40 +0900 Subject: [PATCH] feat: now token can be undefined --- tools/getIssue.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/getIssue.ts b/tools/getIssue.ts index 2cd779b..64177b0 100644 --- a/tools/getIssue.ts +++ b/tools/getIssue.ts @@ -14,9 +14,14 @@ import "https://deno.land/std@0.136.0/dotenv/load.ts"; * console.log(issues); * ``` */ -export async function getIssues(repo: string, token: string): Promise { +export async function getIssues(repo: string, token?: string): Promise { //check https://docs.github.com/en/rest/reference/issues#list-repository-issues - const res = await fetch(`https://api.github.com/repos/${repo}/issues?per_page=100&labels=feature&state=all`, { + const url = `https://api.github.com/repos/${repo}/issues?per_page=100`; + if(!token) { + const res = await fetch(url); + return await res.json(); + } + const res = await fetch(url, { headers: { Accept: 'application/vnd.github.v3+json', Authorization: `Token ${token}` @@ -28,15 +33,7 @@ export async function getIssues(repo: string, token: string): Promise { if (import.meta.main) { const args = parse(Deno.args); - 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) { - console.error("GITHUB_TOKEN is not set"); - Deno.exit(1); - } + let token = args.token ?? Deno.env.get("GITHUB_TOKEN"); const issues = await getIssues("vi117/scrap-yard", token); issues.sort((a, b) => a.number - b.number); const content = JSON.stringify(issues, null, 2);