refact: add github api type

This commit is contained in:
monoid 2022-04-19 19:53:00 +09:00
parent 79d8b321a5
commit 9d18600437
2 changed files with 85 additions and 12 deletions

View File

@ -1,15 +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";
type Issue = {
id: number;
url: string;
title: string;
body: string;
number: number,
labels: {
name: string;
}[]
}
/** /**
* get issue from github * get issue from github
* @param repo repository name with owner (e.g. denoland/deno) * @param repo repository name with owner (e.g. denoland/deno)
@ -21,8 +12,9 @@ type Issue = {
* console.log(issues); * console.log(issues);
* ``` * ```
*/ */
async function getIssues(repo: string, token: string): Promise<Issue[]> { export async function getIssues(repo: string, token: string): Promise<Issue[]> {
const res = await fetch(`https://api.github.com/repos/${repo}/issues?per_page=100`, { //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`, {
headers: { headers: {
Accept: 'application/vnd.github.v3+json', Accept: 'application/vnd.github.v3+json',
Authorization: `Token ${token}` Authorization: `Token ${token}`

81
tools/githubType.ts Normal file
View File

@ -0,0 +1,81 @@
export type User = {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
};
export type Label = {
id: number;
node_id: string;
url: string;
name: string;
description: string;
color: string;
default: boolean;
};
export type Milestone = {
url: string;
html_url: string;
labels_url: string;
id: number;
node_id: string;
number: number;
state: string;
title: string;
description: string;
creator: User;
open_issues: number;
closed_issues: number;
created_at: string;
updated_at: string;
closed_at?: string;
due_on: string;
};
export type PullRequest = {
url: string;
html_url: string;
diff_url: string;
patch_url: string;
};
export type Issue = {
id: number;
node_id: string;
url: string;
repository_url: string;
labels_url: string;
comments_url: string;
events_url: string;
html_url: string;
number: number;
state: string;
title: string;
body: string;
user: User;
labels: Label[];
assignee: User;
assignees: User[];
milestone: any;
locked: boolean;
active_lock_reason: string;
comments: number;
pull_request: PullRequest;
closed_at?: string;
created_at: string;
updated_at: string;
closed_by: User;
author_association: string;
};