Edits history of script submission #23391 for ' List Epic Issues (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})`,
      }))
    }
    
    export type DynSelect_epic_id = string
    
    // Resolver: the chosen board's epics (first 50).
    export async function epic_id(auth: RT.Jira, board_id: string) {
      if (!board_id) return []
      const { values } = await get(
        auth,
        `/rest/agile/1.0/board/${board_id}/epic?maxResults=50`
      )
      return values.map(
        (e: { id: number; key: string; name?: string; summary?: string }) => ({
          value: String(e.id),
          label: `${e.name || e.summary || e.id} (${e.key})`,
        })
      )
    }
    
    /**
     * List Epic Issues
     * List the issues that belong to an epic on a board. Works on company-managed boards only; for a team-managed project, use Search Issues with JQL with `parent = EPIC-KEY` instead.
     */
    export async function main(
      auth: RT.Jira,
      board_id: DynSelect_board_id,
      epic_id: DynSelect_epic_id,
      jql: string | undefined,
      fields: string[] | undefined,
      expand: string | undefined,
      start_at: number | undefined,
      max_results: number | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}/epic/${epic_id}/issue`
      )
      if (jql != null && jql !== "") {
        url.searchParams.append("jql", jql)
      }
      if (fields?.length) {
        url.searchParams.append("fields", fields.join(","))
      }
      if (expand != null && expand !== "") {
        url.searchParams.append("expand", expand)
      }
      if (start_at != null) {
        url.searchParams.append("startAt", String(start_at))
      }
      if (max_results != null) {
        url.searchParams.append("maxResults", String(max_results))
      }
    
      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