1 | |
2 |
|
3 | |
4 | * Update Project |
5 | * Update a project. Only the fields you set are changed. status_id comes from List Project Statuses; label_ids (from List Project Labels) replaces all labels. Dates are YYYY-MM-DD. Priority: 0 none, 1 urgent, 2 high, 3 medium, 4 low. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Linear, |
9 | project_id: string, |
10 | name: string | undefined, |
11 | description: string | undefined, |
12 | status_id: string | undefined, |
13 | lead_id: string | undefined, |
14 | priority: number | undefined, |
15 | start_date: string | undefined, |
16 | target_date: string | undefined, |
17 | label_ids: string[] | undefined |
18 | ) { |
19 | const response = await fetch("https://api.linear.app/graphql", { |
20 | method: "POST", |
21 | headers: { |
22 | Authorization: auth.apiKey, |
23 | "Content-Type": "application/json", |
24 | Accept: "application/json", |
25 | }, |
26 | body: JSON.stringify({ |
27 | query: `mutation ($id: String!, $input: ProjectUpdateInput!) { projectUpdate(id: $id, input: $input) { success project { id name description url priority progress startDate targetDate updatedAt status { id name type } lead { id name } labels { nodes { id name } } teams { nodes { id key } } } } }`, |
28 | variables: { |
29 | id: project_id, |
30 | input: { |
31 | name: name || undefined, |
32 | description: description || undefined, |
33 | statusId: status_id || undefined, |
34 | leadId: lead_id || undefined, |
35 | priority: priority ?? undefined, |
36 | startDate: start_date || undefined, |
37 | targetDate: target_date || undefined, |
38 | labelIds: label_ids?.length ? label_ids : undefined, |
39 | }, |
40 | }, |
41 | }), |
42 | }) |
43 |
|
44 | if (!response.ok) { |
45 | throw new Error(`${response.status} ${await response.text()}`) |
46 | } |
47 |
|
48 | const { data, errors } = await response.json() |
49 | if (errors) { |
50 | throw new Error(JSON.stringify(errors)) |
51 | } |
52 |
|
53 | return data.projectUpdate |
54 | } |
55 |
|