From 82a66202fc74ac2668885fc93d8ca73eb05b0312 Mon Sep 17 00:00:00 2001 From: monoid Date: Tue, 19 Apr 2022 18:26:47 +0900 Subject: [PATCH] feat: add tools --- .vscode/settings.json | 4 ++++ tools/README.md | 11 +++++++++++ tools/getIssue.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 tools/README.md create mode 100644 tools/getIssue.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a0ec965 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "deno.enable": true, + "deno.enablePaths": ["tools/"] +} \ No newline at end of file diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..845960c --- /dev/null +++ b/tools/README.md @@ -0,0 +1,11 @@ +# Tools + +## getIssue + +Github token을 받아서 최신 100개의 Issues 들의 내용을 긁어옵니다. +```sh +deno run --allow-net --allow-env getIssue.ts 'YOUR GIHTUB TOKEN' +``` +으로 실행하면 됩니다. + +토큰을 발급받기 위해선 [다음 링크](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)를 참조하면 됩니다. \ No newline at end of file diff --git a/tools/getIssue.ts b/tools/getIssue.ts new file mode 100644 index 0000000..e75458e --- /dev/null +++ b/tools/getIssue.ts @@ -0,0 +1,43 @@ +#! /usr/bin/env deno run --allow-net --allow-env + +type Issue = { + id: number; + url: string; + title: string; + body: string; + 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 { + 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); + console.log(issues.map(i => `# ${i.title}\n${i.body}`).join("\n\n")); +} \ No newline at end of file