1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Get workflows paginated |
8 | * Returns a [paginated](#pagination) list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned. |
9 |
|
10 | This operation does not return next-gen workflows. |
11 |
|
12 | **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg). |
13 | */ |
14 | export async function main( |
15 | auth: Jira, |
16 | startAt: string | undefined, |
17 | maxResults: string | undefined, |
18 | workflowName: string | undefined, |
19 | expand: string | undefined, |
20 | queryString: string | undefined, |
21 | orderBy: |
22 | | "name" |
23 | | "-name" |
24 | | "+name" |
25 | | "created" |
26 | | "-created" |
27 | | "+created" |
28 | | "updated" |
29 | | "+updated" |
30 | | "-updated" |
31 | | undefined, |
32 | isActive: string | undefined |
33 | ) { |
34 | const url = new URL( |
35 | `https://${auth.domain}.atlassian.net/rest/api/2/workflow/search` |
36 | ); |
37 | for (const [k, v] of [ |
38 | ["startAt", startAt], |
39 | ["maxResults", maxResults], |
40 | ["workflowName", workflowName], |
41 | ["expand", expand], |
42 | ["queryString", queryString], |
43 | ["orderBy", orderBy], |
44 | ["isActive", isActive], |
45 | ]) { |
46 | if (v !== undefined && v !== "") { |
47 | url.searchParams.append(k, v); |
48 | } |
49 | } |
50 | const response = await fetch(url, { |
51 | method: "GET", |
52 | headers: { |
53 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
54 | }, |
55 | body: undefined, |
56 | }); |
57 | if (!response.ok) { |
58 | const text = await response.text(); |
59 | throw new Error(`${response.status} ${text}`); |
60 | } |
61 | return await response.json(); |
62 | } |
63 |
|