feat: add tools
This commit is contained in:
parent
e74e2cbc2d
commit
82a66202fc
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"deno.enablePaths": ["tools/"]
|
||||
}
|
11
tools/README.md
Normal file
11
tools/README.md
Normal file
@ -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)를 참조하면 됩니다.
|
43
tools/getIssue.ts
Normal file
43
tools/getIssue.ts
Normal file
@ -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<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);
|
||||
console.log(issues.map(i => `# ${i.title}\n${i.body}`).join("\n\n"));
|
||||
}
|
Loading…
Reference in New Issue
Block a user