1 | |
2 |
|
3 | |
4 | * Create Initiative |
5 | * Create an initiative, a workspace-level goal that groups projects. Status: Planned, Active, Completed (default Planned). target_date is YYYY-MM-DD. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Linear, |
9 | name: string, |
10 | description: string | undefined, |
11 | content: string | undefined, |
12 | status: |
13 | "Planned" | "Active" | "Completed" | "Proposed" | "Canceled" | undefined, |
14 | owner_id: string | undefined, |
15 | target_date: string | undefined, |
16 | color: string | undefined |
17 | ) { |
18 | const response = await fetch("https://api.linear.app/graphql", { |
19 | method: "POST", |
20 | headers: { |
21 | Authorization: auth.apiKey, |
22 | "Content-Type": "application/json", |
23 | Accept: "application/json", |
24 | }, |
25 | body: JSON.stringify({ |
26 | query: `mutation ($input: InitiativeCreateInput!) { initiativeCreate(input: $input) { success initiative { id name description url status health targetDate createdAt updatedAt archivedAt owner { id name } projects { nodes { id name } } } } }`, |
27 | variables: { |
28 | input: { |
29 | name, |
30 | description: description || undefined, |
31 | content: content || undefined, |
32 | status: status || undefined, |
33 | ownerId: owner_id || undefined, |
34 | targetDate: target_date || undefined, |
35 | color: color || undefined, |
36 | }, |
37 | }, |
38 | }), |
39 | }) |
40 |
|
41 | if (!response.ok) { |
42 | throw new Error(`${response.status} ${await response.text()}`) |
43 | } |
44 |
|
45 | const { data, errors } = await response.json() |
46 | if (errors) { |
47 | throw new Error(JSON.stringify(errors)) |
48 | } |
49 |
|
50 | return data.initiativeCreate |
51 | } |
52 |
|