1 | |
2 |
|
3 | export type DynSelect_team_id = string |
4 |
|
5 | |
6 | export async function team_id(auth: RT.Linear) { |
7 | const response = await fetch("https://api.linear.app/graphql", { |
8 | method: "POST", |
9 | headers: { |
10 | Authorization: auth.apiKey, |
11 | "Content-Type": "application/json", |
12 | Accept: "application/json", |
13 | }, |
14 | body: JSON.stringify({ |
15 | query: "{ teams(first: 250) { nodes { id key name } } }", |
16 | }), |
17 | }) |
18 | if (!response.ok) { |
19 | throw new Error(`${response.status} ${await response.text()}`) |
20 | } |
21 | const { data } = (await response.json()) as { |
22 | data: { teams: { nodes: { id: string; key: string; name: string }[] } } |
23 | } |
24 | return data.teams.nodes.map((t) => ({ |
25 | value: t.id, |
26 | label: `${t.name} (${t.key})`, |
27 | })) |
28 | } |
29 |
|
30 | |
31 | * List Issues |
32 | * List issues, optionally filtered by team, project, workflow state, assignee or label names. Paginate with after = pageInfo.endCursor. |
33 | */ |
34 | export async function main( |
35 | auth: RT.Linear, |
36 | team_id: DynSelect_team_id | undefined, |
37 | project_id: string | undefined, |
38 | state_id: string | undefined, |
39 | assignee_id: string | undefined, |
40 | label_names: string[] | undefined, |
41 | order_by: "createdAt" | "updatedAt" = "updatedAt", |
42 | include_archived: boolean = false, |
43 | first: number = 50, |
44 | after: string | undefined |
45 | ) { |
46 | const filter: { [key: string]: any } = {} |
47 | if (team_id) filter.team = { id: { eq: team_id } } |
48 | if (project_id) filter.project = { id: { eq: project_id } } |
49 | if (state_id) filter.state = { id: { eq: state_id } } |
50 | if (assignee_id) filter.assignee = { id: { eq: assignee_id } } |
51 | if (label_names?.length) |
52 | filter.labels = { some: { name: { in: label_names } } } |
53 |
|
54 | const response = await fetch("https://api.linear.app/graphql", { |
55 | method: "POST", |
56 | headers: { |
57 | Authorization: auth.apiKey, |
58 | "Content-Type": "application/json", |
59 | Accept: "application/json", |
60 | }, |
61 | body: JSON.stringify({ |
62 | query: `query ($filter: IssueFilter, $orderBy: PaginationOrderBy, $includeArchived: Boolean, $first: Int, $after: String) { issues(filter: $filter, orderBy: $orderBy, includeArchived: $includeArchived, first: $first, after: $after) { nodes { id identifier title description url priority priorityLabel estimate dueDate createdAt updatedAt archivedAt state { id name type } assignee { id name email } team { id key name } project { id name } cycle { id number } parent { id identifier } labels { nodes { id name } } } pageInfo { hasNextPage endCursor } } }`, |
63 | variables: { |
64 | filter, |
65 | orderBy: order_by, |
66 | includeArchived: include_archived, |
67 | first, |
68 | after: after || undefined, |
69 | }, |
70 | }), |
71 | }) |
72 |
|
73 | if (!response.ok) { |
74 | throw new Error(`${response.status} ${await response.text()}`) |
75 | } |
76 |
|
77 | const { data, errors } = await response.json() |
78 | if (errors) { |
79 | throw new Error(JSON.stringify(errors)) |
80 | } |
81 |
|
82 | return data.issues |
83 | } |
84 |
|