1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Create a label |
6 | * |
7 | */ |
8 | export async function main( |
9 | auth: Github, |
10 | owner: string, |
11 | repo: string, |
12 | body: { |
13 | color?: string; |
14 | description?: string; |
15 | name: string; |
16 | [k: string]: unknown; |
17 | } |
18 | ) { |
19 | const url = new URL(`https://api.github.com/repos/${owner}/${repo}/labels`); |
20 |
|
21 | const response = await fetch(url, { |
22 | method: "POST", |
23 | headers: { |
24 | "Content-Type": "application/json", |
25 | Authorization: "Bearer " + auth.token, |
26 | }, |
27 | body: JSON.stringify(body), |
28 | }); |
29 | if (!response.ok) { |
30 | const text = await response.text(); |
31 | throw new Error(`${response.status} ${text}`); |
32 | } |
33 | return await response.json(); |
34 | } |
35 |
|