1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Create workflow transition property |
8 | * Adds a property to a workflow transition. Transition properties are used to change the behavior of a transition. For more information, see [Transition properties](https://confluence.atlassian.com/x/zIhKLg#Advancedworkflowconfiguration-transitionproperties) and [Workflow properties](https://confluence.atlassian.com/x/JYlKLg). |
9 |
|
10 | **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg). |
11 | */ |
12 | export async function main( |
13 | auth: Jira, |
14 | transitionId: string, |
15 | key: string | undefined, |
16 | workflowName: string | undefined, |
17 | workflowMode: "live" | "draft" | undefined, |
18 | body: { id?: string; key?: string; value: string; [k: string]: unknown } |
19 | ) { |
20 | const url = new URL( |
21 | `https://${auth.domain}.atlassian.net/rest/api/2/workflow/transitions/${transitionId}/properties` |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["key", key], |
25 | ["workflowName", workflowName], |
26 | ["workflowMode", workflowMode], |
27 | ]) { |
28 | if (v !== undefined && v !== "") { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|