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 | * Create Future Sprint |
29 | * Create a sprint in the future state on a scrum board. Dates are ISO 8601 date-times, e.g. `2026-01-15T09:00:00.000Z`. |
30 | */ |
31 | export async function main( |
32 | auth: RT.Jira, |
33 | board_id: DynSelect_board_id, |
34 | name: string, |
35 | goal: string | undefined, |
36 | start_date: string | undefined, |
37 | end_date: string | undefined |
38 | ) { |
39 | const url = new URL( |
40 | `https://${auth.domain}.atlassian.net/rest/agile/1.0/sprint` |
41 | ) |
42 |
|
43 | const body: { [key: string]: any } = { originBoardId: Number(board_id), name } |
44 | if (goal != null && goal !== "") { |
45 | body.goal = goal |
46 | } |
47 | if (start_date != null && start_date !== "") { |
48 | body.startDate = start_date |
49 | } |
50 | if (end_date != null && end_date !== "") { |
51 | body.endDate = end_date |
52 | } |
53 |
|
54 | const response = await fetch(url, { |
55 | method: "POST", |
56 | headers: { |
57 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
58 | "Content-Type": "application/json", |
59 | Accept: "application/json", |
60 | }, |
61 | body: JSON.stringify(body), |
62 | }) |
63 |
|
64 | if (!response.ok) { |
65 | throw new Error(`${response.status} ${await response.text()}`) |
66 | } |
67 |
|
68 | return await response.json() |
69 | } |
70 |
|