Update workflow transition rule configurations

Updates configuration of workflow transition rules.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Update workflow transition rule configurations
8
 * Updates configuration of workflow transition rules.
9
 */
10
export async function main(
11
  auth: Jira,
12
  body: {
13
    workflows: {
14
      conditions?: {
15
        configuration: { disabled?: boolean; tag?: string; value: string };
16
        id: string;
17
        key: string;
18
        transition?: { id: number; name: string };
19
      }[];
20
      postFunctions?: {
21
        configuration: { disabled?: boolean; tag?: string; value: string };
22
        id: string;
23
        key: string;
24
        transition?: { id: number; name: string };
25
      }[];
26
      validators?: {
27
        configuration: { disabled?: boolean; tag?: string; value: string };
28
        id: string;
29
        key: string;
30
        transition?: { id: number; name: string };
31
      }[];
32
      workflowId: { draft: boolean; name: string };
33
    }[];
34
  }
35
) {
36
  const url = new URL(
37
    `https://${auth.domain}.atlassian.net/rest/api/2/workflow/rule/config`
38
  );
39

40
  const response = await fetch(url, {
41
    method: "PUT",
42
    headers: {
43
      "Content-Type": "application/json",
44
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54