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 | * Get Sprint |
44 | * Get a sprint by ID: name, state, goal, start and end dates. 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 | ) { |
51 | const url = new URL( |
52 | `https://${auth.domain}.atlassian.net/rest/agile/1.0/sprint/${sprint_id}` |
53 | ) |
54 |
|
55 | const response = await fetch(url, { |
56 | method: "GET", |
57 | headers: { |
58 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
59 | Accept: "application/json", |
60 | }, |
61 | }) |
62 |
|
63 | if (!response.ok) { |
64 | throw new Error(`${response.status} ${await response.text()}`) |
65 | } |
66 |
|
67 | return await response.json() |
68 | } |
69 |
|