1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * List repository issues |
6 | * List issues in a repository. |
7 | */ |
8 | export async function main( |
9 | auth: Github, |
10 | owner: string, |
11 | repo: string, |
12 | milestone: string | undefined, |
13 | state: "open" | "closed" | "all" | undefined, |
14 | assignee: string | undefined, |
15 | creator: string | undefined, |
16 | mentioned: string | undefined, |
17 | labels: string | undefined, |
18 | sort: "created" | "updated" | "comments" | undefined, |
19 | direction: "asc" | "desc" | undefined, |
20 | since: string | undefined, |
21 | per_page: string | undefined, |
22 | page: string | undefined |
23 | ) { |
24 | const url = new URL(`https://api.github.com/repos/${owner}/${repo}/issues`); |
25 | for (const [k, v] of [ |
26 | ["milestone", milestone], |
27 | ["state", state], |
28 | ["assignee", assignee], |
29 | ["creator", creator], |
30 | ["mentioned", mentioned], |
31 | ["labels", labels], |
32 | ["sort", sort], |
33 | ["direction", direction], |
34 | ["since", since], |
35 | ["per_page", per_page], |
36 | ["page", page], |
37 | ]) { |
38 | if (v !== undefined && v !== "") { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "GET", |
44 | headers: { |
45 | Authorization: "Bearer " + auth.token, |
46 | }, |
47 | body: undefined, |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|