1 | |
2 |
|
3 | |
4 | * Create Issue |
5 | * Open an issue in a repository, optionally with assignees, labels and a milestone. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Github, |
9 | owner: string, |
10 | repo: string, |
11 | title: string, |
12 | body: string | undefined, |
13 | assignees: string[] | undefined, |
14 | labels: string[] | undefined, |
15 | milestone: number | undefined |
16 | ) { |
17 | const response = await fetch( |
18 | `https://api.github.com/repos/${owner}/${repo}/issues`, |
19 | { |
20 | method: "POST", |
21 | headers: { |
22 | Authorization: `Bearer ${auth.token}`, |
23 | "Content-Type": "application/json", |
24 | Accept: "application/vnd.github+json", |
25 | "X-GitHub-Api-Version": "2022-11-28", |
26 | }, |
27 | body: JSON.stringify({ |
28 | title, |
29 | body: body || undefined, |
30 | assignees: assignees?.length ? assignees : undefined, |
31 | labels: labels?.length ? labels : undefined, |
32 | milestone: milestone ?? undefined, |
33 | }), |
34 | } |
35 | ) |
36 |
|
37 | if (!response.ok) { |
38 | throw new Error(`${response.status} ${await response.text()}`) |
39 | } |
40 |
|
41 | return await response.json() |
42 | } |
43 |
|