1 | |
2 |
|
3 | async function get(auth: RT.Jira, path: string) { |
4 | const response = await fetch(`https://${auth.domain}.atlassian.net${path}`, { |
5 | headers: { |
6 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
7 | Accept: "application/json", |
8 | }, |
9 | }) |
10 | if (!response.ok) { |
11 | throw new Error(`${response.status} ${await response.text()}`) |
12 | } |
13 | return await response.json() |
14 | } |
15 |
|
16 | export type DynSelect_board_id = string |
17 |
|
18 | |
19 | export async function board_id(auth: RT.Jira) { |
20 | const { values } = await get(auth, "/rest/agile/1.0/board?maxResults=50") |
21 | return values.map((b: { id: number; name: string; type: string }) => ({ |
22 | value: String(b.id), |
23 | label: `${b.name} (${b.type})`, |
24 | })) |
25 | } |
26 |
|
27 | export type DynSelect_sprint_id = string |
28 |
|
29 | |
30 | export async function sprint_id(auth: RT.Jira, board_id: string) { |
31 | if (!board_id) return [] |
32 | const { values } = await get( |
33 | auth, |
34 | `/rest/agile/1.0/board/${board_id}/sprint?maxResults=50` |
35 | ) |
36 | return values.map((s: { id: number; name: string; state: string }) => ({ |
37 | value: String(s.id), |
38 | label: `${s.name} (${s.state})`, |
39 | })) |
40 | } |
41 |
|
42 | |
43 | * List Sprint Issues |
44 | * List the issues in a sprint, optionally narrowed by a JQL query. Paginated with `start_at` / `max_results`. The board only feeds the sprint dropdown. |
45 | */ |
46 | export async function main( |
47 | auth: RT.Jira, |
48 | board_id: DynSelect_board_id | undefined, |
49 | sprint_id: DynSelect_sprint_id, |
50 | jql: string | undefined, |
51 | fields: string[] | undefined, |
52 | expand: string | undefined, |
53 | start_at: number | undefined, |
54 | max_results: number | undefined |
55 | ) { |
56 | const url = new URL( |
57 | `https://${auth.domain}.atlassian.net/rest/agile/1.0/sprint/${sprint_id}/issue` |
58 | ) |
59 | if (jql != null && jql !== "") { |
60 | url.searchParams.append("jql", jql) |
61 | } |
62 | if (fields?.length) { |
63 | url.searchParams.append("fields", fields.join(",")) |
64 | } |
65 | if (expand != null && expand !== "") { |
66 | url.searchParams.append("expand", expand) |
67 | } |
68 | if (start_at != null) { |
69 | url.searchParams.append("startAt", String(start_at)) |
70 | } |
71 | if (max_results != null) { |
72 | url.searchParams.append("maxResults", String(max_results)) |
73 | } |
74 |
|
75 | const response = await fetch(url, { |
76 | method: "GET", |
77 | headers: { |
78 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
79 | Accept: "application/json", |
80 | }, |
81 | }) |
82 |
|
83 | if (!response.ok) { |
84 | throw new Error(`${response.status} ${await response.text()}`) |
85 | } |
86 |
|
87 | return await response.json() |
88 | } |
89 |
|