Edits history of script submission #23386 for ' Get Board (jira)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    async function get(auth: RT.Jira, path: string) {
      const response = await fetch(`https://${auth.domain}.atlassian.net${path}`, {
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          Accept: "application/json",
        },
      })
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      return await response.json()
    }
    
    export type DynSelect_board_id = string
    
    // Resolver: the site's boards (first 50).
    export async function board_id(auth: RT.Jira) {
      const { values } = await get(auth, "/rest/agile/1.0/board?maxResults=50")
      return values.map((b: { id: number; name: string; type: string }) => ({
        value: String(b.id),
        label: `${b.name} (${b.type})`,
      }))
    }
    
    /**
     * Get Board
     * Get a Jira Software board by ID, including its type and the project it belongs to.
     */
    export async function main(auth: RT.Jira, board_id: DynSelect_board_id) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}`
      )
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago