0

Bulk update workflows

by
Published Nov 2, 2023

Update workflows and related statuses. **[Permissions](#permissions) required:** * *Administer Jira* project permission to create all, including global-scoped, workflows * *Administer projects* project permissions to create project-scoped workflows

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 527 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Bulk update workflows
    8
     * Update workflows and related statuses.
    9
    
    
    10
    **[Permissions](#permissions) required:**
    11
    
    
    12
     *  *Administer Jira* project permission to create all, including global-scoped, workflows
    13
     *  *Administer projects* project permissions to create project-scoped workflows
    14
     */
    15
    export async function main(
    16
      auth: Jira,
    17
      expand: string | undefined,
    18
      body: {
    19
        statuses: {
    20
          description?: string;
    21
          id?: string;
    22
          name: string;
    23
          statusCategory: "TODO" | "IN_PROGRESS" | "DONE";
    24
          statusReference: string;
    25
          [k: string]: unknown;
    26
        }[];
    27
        workflows: {
    28
          defaultStatusMappings?: {
    29
            newStatusReference: string;
    30
            oldStatusReference: string;
    31
            [k: string]: unknown;
    32
          }[];
    33
          description?: string;
    34
          id: string;
    35
          startPointLayout?: { x?: number; y?: number };
    36
          statusMappings?: {
    37
            issueTypeId: string;
    38
            projectId: string;
    39
            statusMigrations: {
    40
              newStatusReference: string;
    41
              oldStatusReference: string;
    42
              [k: string]: unknown;
    43
            }[];
    44
            [k: string]: unknown;
    45
          }[];
    46
          statuses: {
    47
            layout?: { x?: number; y?: number };
    48
            properties: { [k: string]: string };
    49
            statusReference: string;
    50
            [k: string]: unknown;
    51
          }[];
    52
          transitions: {
    53
            actions?: {
    54
              id?: string;
    55
              parameters?: { [k: string]: string };
    56
              ruleKey: string;
    57
            }[];
    58
            conditions?: {
    59
              conditionGroups?: {}[];
    60
              conditions?: {
    61
                id?: string;
    62
                parameters?: { [k: string]: string };
    63
                ruleKey: string;
    64
              }[];
    65
              operation: "ANY" | "ALL";
    66
            };
    67
            customIssueEventId?: string;
    68
            description?: string;
    69
            from?: { port?: number; statusReference: string }[];
    70
            id: string;
    71
            name: string;
    72
            properties?: { [k: string]: string };
    73
            to?: { port?: number; statusReference: string };
    74
            transitionScreen?: {
    75
              id?: string;
    76
              parameters?: { [k: string]: string };
    77
              ruleKey: string;
    78
            };
    79
            triggers?: {
    80
              id?: string;
    81
              parameters: { [k: string]: string };
    82
              ruleKey: string;
    83
            }[];
    84
            type: "INITIAL" | "GLOBAL" | "DIRECTED";
    85
            validators?: {
    86
              id?: string;
    87
              parameters?: { [k: string]: string };
    88
              ruleKey: string;
    89
            }[];
    90
            [k: string]: unknown;
    91
          }[];
    92
          version: { id: string; versionNumber: number };
    93
          [k: string]: unknown;
    94
        }[];
    95
      }
    96
    ) {
    97
      const url = new URL(
    98
        `https://${auth.domain}.atlassian.net/rest/api/2/workflows/update`
    99
      );
    100
      for (const [k, v] of [["expand", expand]]) {
    101
        if (v !== undefined && v !== "") {
    102
          url.searchParams.append(k, v);
    103
        }
    104
      }
    105
      const response = await fetch(url, {
    106
        method: "POST",
    107
        headers: {
    108
          "Content-Type": "application/json",
    109
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    110
        },
    111
        body: JSON.stringify(body),
    112
      });
    113
      if (!response.ok) {
    114
        const text = await response.text();
    115
        throw new Error(`${response.status} ${text}`);
    116
      }
    117
      return await response.json();
    118
    }
    119