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 | |
28 | * List Epics |
29 | * List the epics on a board, optionally only those done or not done. Paginated with `start_at` / `max_results`. |
30 | */ |
31 | export async function main( |
32 | auth: RT.Jira, |
33 | board_id: DynSelect_board_id, |
34 | done: "true" | "false" | undefined, |
35 | start_at: number | undefined, |
36 | max_results: number | undefined |
37 | ) { |
38 | const url = new URL( |
39 | `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}/epic` |
40 | ) |
41 | if (done != null && done !== "") { |
42 | url.searchParams.append("done", done) |
43 | } |
44 | if (start_at != null) { |
45 | url.searchParams.append("startAt", String(start_at)) |
46 | } |
47 | if (max_results != null) { |
48 | url.searchParams.append("maxResults", String(max_results)) |
49 | } |
50 |
|
51 | const response = await fetch(url, { |
52 | method: "GET", |
53 | headers: { |
54 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
55 | Accept: "application/json", |
56 | }, |
57 | }) |
58 |
|
59 | if (!response.ok) { |
60 | throw new Error(`${response.status} ${await response.text()}`) |
61 | } |
62 |
|
63 | return await response.json() |
64 | } |
65 |
|