1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Get custom field configurations |
8 | * Returns a [paginated](#pagination) list of configurations for a custom field of a [type](https://developer. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | fieldIdOrKey: string, |
13 | id: string | undefined, |
14 | fieldContextId: string | undefined, |
15 | issueId: string | undefined, |
16 | projectKeyOrId: string | undefined, |
17 | issueTypeId: string | undefined, |
18 | startAt: string | undefined, |
19 | maxResults: string | undefined |
20 | ) { |
21 | const url = new URL( |
22 | `https://${auth.domain}.atlassian.net/rest/api/2/app/field/${fieldIdOrKey}/context/configuration` |
23 | ); |
24 | for (const [k, v] of [ |
25 | ["id", id], |
26 | ["fieldContextId", fieldContextId], |
27 | ["issueId", issueId], |
28 | ["projectKeyOrId", projectKeyOrId], |
29 | ["issueTypeId", issueTypeId], |
30 | ["startAt", startAt], |
31 | ["maxResults", maxResults], |
32 | ]) { |
33 | if (v !== undefined && v !== "") { |
34 | url.searchParams.append(k, v); |
35 | } |
36 | } |
37 | const response = await fetch(url, { |
38 | method: "GET", |
39 | headers: { |
40 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
41 | }, |
42 | body: undefined, |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|