1 | |
2 |
|
3 | |
4 | * Get Issue |
5 | * Get an issue by ID or key. `fields` narrows the returned fields (`*all`, `*navigable`, or field IDs, `-` prefix to exclude); `expand` accepts a comma-separated list of `renderedFields`, `names`, `schema`, `transitions`, `editmeta`, `changelog`, `versionedRepresentations`. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Jira, |
9 | issue_id_or_key: string, |
10 | fields: string[] | undefined, |
11 | expand: string | undefined, |
12 | properties: string[] | undefined, |
13 | fields_by_keys: boolean | undefined, |
14 | update_history: boolean | undefined |
15 | ) { |
16 | const url = new URL( |
17 | `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issue_id_or_key}` |
18 | ) |
19 | if (fields?.length) { |
20 | url.searchParams.append("fields", fields.join(",")) |
21 | } |
22 | if (expand != null && expand !== "") { |
23 | url.searchParams.append("expand", expand) |
24 | } |
25 | if (properties?.length) { |
26 | url.searchParams.append("properties", properties.join(",")) |
27 | } |
28 | if (fields_by_keys) { |
29 | url.searchParams.append("fieldsByKeys", "true") |
30 | } |
31 | if (update_history) { |
32 | url.searchParams.append("updateHistory", "true") |
33 | } |
34 |
|
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
39 | Accept: "application/json", |
40 | }, |
41 | }) |
42 |
|
43 | if (!response.ok) { |
44 | throw new Error(`${response.status} ${await response.text()}`) |
45 | } |
46 |
|
47 | return await response.json() |
48 | } |
49 |
|