1 | |
2 |
|
3 | |
4 | * List Initiatives |
5 | * List initiatives, most recently updated first, optionally filtered by name (contains, case-insensitive) or status. Paginate with after = pageInfo.endCursor. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Linear, |
9 | name: string | undefined, |
10 | status: |
11 | "Planned" | "Active" | "Completed" | "Proposed" | "Canceled" | undefined, |
12 | include_archived: boolean = false, |
13 | first: number = 50, |
14 | after: string | undefined |
15 | ) { |
16 | const filter: { [key: string]: any } = {} |
17 | if (name) filter.name = { containsIgnoreCase: name } |
18 | if (status) filter.status = { eq: status } |
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: `query ($filter: InitiativeFilter, $includeArchived: Boolean, $first: Int, $after: String) { initiatives(filter: $filter, includeArchived: $includeArchived, first: $first, after: $after, orderBy: updatedAt) { nodes { id name description url status health targetDate createdAt updatedAt archivedAt owner { id name } projects { nodes { id name } } } pageInfo { hasNextPage endCursor } } }`, |
28 | variables: { |
29 | filter, |
30 | includeArchived: include_archived, |
31 | first, |
32 | after: after || undefined, |
33 | }, |
34 | }), |
35 | }) |
36 |
|
37 | if (!response.ok) { |
38 | throw new Error(`${response.status} ${await response.text()}`) |
39 | } |
40 |
|
41 | const { data, errors } = await response.json() |
42 | if (errors) { |
43 | throw new Error(JSON.stringify(errors)) |
44 | } |
45 |
|
46 | return data.initiatives |
47 | } |
48 |
|