1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Create workflow |
8 | * Creates a workflow. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | body: { |
13 | description?: string; |
14 | name: string; |
15 | statuses: { id: string; properties?: { [k: string]: string } }[]; |
16 | transitions: { |
17 | description?: string; |
18 | from?: string[]; |
19 | name: string; |
20 | properties?: { [k: string]: string }; |
21 | rules?: { |
22 | conditions?: { |
23 | conditions?: {}[]; |
24 | configuration?: { [k: string]: { [k: string]: unknown } }; |
25 | operator?: "AND" | "OR"; |
26 | type?: string; |
27 | }; |
28 | postFunctions?: { |
29 | configuration?: { [k: string]: { [k: string]: unknown } }; |
30 | type: string; |
31 | }[]; |
32 | validators?: { |
33 | configuration?: { [k: string]: { [k: string]: unknown } }; |
34 | type: string; |
35 | }[]; |
36 | }; |
37 | screen?: { id: string }; |
38 | to: string; |
39 | type: "global" | "initial" | "directed"; |
40 | }[]; |
41 | } |
42 | ) { |
43 | const url = new URL( |
44 | `https://${auth.domain}.atlassian.net/rest/api/2/workflow` |
45 | ); |
46 |
|
47 | const response = await fetch(url, { |
48 | method: "POST", |
49 | headers: { |
50 | "Content-Type": "application/json", |
51 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
52 | }, |
53 | body: JSON.stringify(body), |
54 | }); |
55 | if (!response.ok) { |
56 | const text = await response.text(); |
57 | throw new Error(`${response.status} ${text}`); |
58 | } |
59 | return await response.json(); |
60 | } |
61 |
|