0

Set issue navigator default columns

by
Published Nov 2, 2023

Sets the default issue navigator columns.

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
     * Set issue navigator default columns
    8
     * Sets the default issue navigator columns.
    9
     */
    10
    export async function main(auth: Jira, body: { columns?: string[] }) {
    11
      const url = new URL(
    12
        `https://${auth.domain}.atlassian.net/rest/api/2/settings/columns`
    13
      );
    14
    
    
    15
      const formData = new FormData();
    16
      for (const [k, v] of Object.entries(body)) {
    17
        if (v !== undefined && v !== "") {
    18
          formData.append(k, String(v));
    19
        }
    20
      }
    21
      const response = await fetch(url, {
    22
        method: "PUT",
    23
        headers: {
    24
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    25
        },
    26
        body: formData,
    27
      });
    28
      if (!response.ok) {
    29
        const text = await response.text();
    30
        throw new Error(`${response.status} ${text}`);
    31
      }
    32
      return await response.text();
    33
    }
    34