1 | |
2 |
|
3 | |
4 | * Create Label |
5 | * Create an issue label. Leave team_id empty for a workspace-wide label. color is a hex string such as #5e6ad2. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Linear, |
9 | name: string, |
10 | team_id: string | undefined, |
11 | color: string | undefined, |
12 | description: string | undefined, |
13 | parent_id: string | undefined |
14 | ) { |
15 | const response = await fetch("https://api.linear.app/graphql", { |
16 | method: "POST", |
17 | headers: { |
18 | Authorization: auth.apiKey, |
19 | "Content-Type": "application/json", |
20 | Accept: "application/json", |
21 | }, |
22 | body: JSON.stringify({ |
23 | query: `mutation ($input: IssueLabelCreateInput!) { issueLabelCreate(input: $input) { success issueLabel { id name color description team { id key } } } }`, |
24 | variables: { |
25 | input: { |
26 | name, |
27 | teamId: team_id || undefined, |
28 | color: color || undefined, |
29 | description: description || undefined, |
30 | parentId: parent_id || undefined, |
31 | }, |
32 | }, |
33 | }), |
34 | }) |
35 |
|
36 | if (!response.ok) { |
37 | throw new Error(`${response.status} ${await response.text()}`) |
38 | } |
39 |
|
40 | const { data, errors } = await response.json() |
41 | if (errors) { |
42 | throw new Error(JSON.stringify(errors)) |
43 | } |
44 |
|
45 | return data.issueLabelCreate |
46 | } |
47 |
|