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_epic_id = string |
28 |
|
29 | |
30 | export async function epic_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}/epic?maxResults=50` |
35 | ) |
36 | return values.map( |
37 | (e: { id: number; key: string; name?: string; summary?: string }) => ({ |
38 | value: String(e.id), |
39 | label: `${e.name || e.summary || e.id} (${e.key})`, |
40 | }) |
41 | ) |
42 | } |
43 |
|
44 | |
45 | * List Epic Issues |
46 | * List the issues that belong to an epic on a board. Works on company-managed boards only; for a team-managed project, use Search Issues with JQL with `parent = EPIC-KEY` instead. |
47 | */ |
48 | export async function main( |
49 | auth: RT.Jira, |
50 | board_id: DynSelect_board_id, |
51 | epic_id: DynSelect_epic_id, |
52 | jql: string | undefined, |
53 | fields: string[] | undefined, |
54 | expand: string | undefined, |
55 | start_at: number | undefined, |
56 | max_results: number | undefined |
57 | ) { |
58 | const url = new URL( |
59 | `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}/epic/${epic_id}/issue` |
60 | ) |
61 | if (jql != null && jql !== "") { |
62 | url.searchParams.append("jql", jql) |
63 | } |
64 | if (fields?.length) { |
65 | url.searchParams.append("fields", fields.join(",")) |
66 | } |
67 | if (expand != null && expand !== "") { |
68 | url.searchParams.append("expand", expand) |
69 | } |
70 | if (start_at != null) { |
71 | url.searchParams.append("startAt", String(start_at)) |
72 | } |
73 | if (max_results != null) { |
74 | url.searchParams.append("maxResults", String(max_results)) |
75 | } |
76 |
|
77 | const response = await fetch(url, { |
78 | method: "GET", |
79 | headers: { |
80 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
81 | Accept: "application/json", |
82 | }, |
83 | }) |
84 |
|
85 | if (!response.ok) { |
86 | throw new Error(`${response.status} ${await response.text()}`) |
87 | } |
88 |
|
89 | return await response.json() |
90 | } |
91 |
|