Edits history of script submission #23362 for ' Get Issue (jira)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Issue
     * Get an issue by ID or key. `fields` narrows the returned fields (`*all`, `*navigable`, or field IDs, `-` prefix to exclude); `expand` accepts a comma-separated list of `renderedFields`, `names`, `schema`, `transitions`, `editmeta`, `changelog`, `versionedRepresentations`.
     */
    export async function main(
      auth: RT.Jira,
      issue_id_or_key: string,
      fields: string[] | undefined,
      expand: string | undefined,
      properties: string[] | undefined,
      fields_by_keys: boolean | undefined,
      update_history: boolean | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issue_id_or_key}`
      )
      if (fields?.length) {
        url.searchParams.append("fields", fields.join(","))
      }
      if (expand != null && expand !== "") {
        url.searchParams.append("expand", expand)
      }
      if (properties?.length) {
        url.searchParams.append("properties", properties.join(","))
      }
      if (fields_by_keys) {
        url.searchParams.append("fieldsByKeys", "true")
      }
      if (update_history) {
        url.searchParams.append("updateHistory", "true")
      }
    
      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 14 days ago