1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Search statuses paginated |
8 | * Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of statuses that match a search on name or project. |
9 |
|
10 | **[Permissions](#permissions) required:** |
11 |
|
12 | * *Administer projects* [project permission.](https://confluence.atlassian.com/x/yodKLg) |
13 | * *Administer Jira* [project permission.](https://confluence.atlassian.com/x/yodKLg) |
14 | */ |
15 | export async function main( |
16 | auth: Jira, |
17 | expand: string | undefined, |
18 | projectId: string | undefined, |
19 | startAt: string | undefined, |
20 | maxResults: string | undefined, |
21 | searchString: string | undefined, |
22 | statusCategory: string | undefined |
23 | ) { |
24 | const url = new URL( |
25 | `https://${auth.domain}.atlassian.net/rest/api/2/statuses/search` |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["expand", expand], |
29 | ["projectId", projectId], |
30 | ["startAt", startAt], |
31 | ["maxResults", maxResults], |
32 | ["searchString", searchString], |
33 | ["statusCategory", statusCategory], |
34 | ]) { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|