Edits history of script submission #23366 for ' Add Attachments to Issue (jira)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import * as wmill from "windmill-client"
    import { S3Object } from "windmill-client"
    
    /**
     * Add Attachments to Issue
     * Attach one or more files from Windmill object storage to an issue. Each file keeps the name at the end of its storage path.
     */
    export async function main(
      auth: RT.Jira,
      issue_id_or_key: string,
      files: S3Object[]
    ) {
      const form = new FormData()
      for (const file of files) {
        const bytes = await wmill.loadS3File(file)
        if (!bytes) {
          throw new Error(`Could not load ${file.s3} from object storage`)
        }
        form.append("file", new Blob([bytes]), file.s3.split("/").pop())
      }
    
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issue_id_or_key}/attachments`
      )
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          "X-Atlassian-Token": "no-check",
          Accept: "application/json",
        },
        body: form,
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago