1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Update workflow transition property |
8 | * Updates a workflow transition by changing the property value. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | transitionId: string, |
13 | key: string | undefined, |
14 | workflowName: string | undefined, |
15 | workflowMode: "live" | "draft" | undefined, |
16 | body: { id?: string; key?: string; value: string; [k: string]: unknown } |
17 | ) { |
18 | const url = new URL( |
19 | `https://${auth.domain}.atlassian.net/rest/api/2/workflow/transitions/${transitionId}/properties` |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["key", key], |
23 | ["workflowName", workflowName], |
24 | ["workflowMode", workflowMode], |
25 | ]) { |
26 | if (v !== undefined && v !== "") { |
27 | url.searchParams.append(k, v); |
28 | } |
29 | } |
30 | const response = await fetch(url, { |
31 | method: "PUT", |
32 | headers: { |
33 | "Content-Type": "application/json", |
34 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
35 | }, |
36 | body: JSON.stringify(body), |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|