Edits history of script submission #23604 for ' Update Script (windmill)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    import * as wmill from "windmill-client"
    
    // windmill-client errors only carry the status text: throw the response body, which says why
    wmill.OpenAPI.interceptors.response.use(async (response) => {
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      return response
    })
    
    export type DynSelect_path = string
    
    export async function path() {
      const paths = await wmill.ScriptService.listScriptPaths({
        workspace: wmill.getWorkspace(),
      })
      return paths.map((p) => ({ value: p, label: p }))
    }
    
    /**
     * Update Script
     * Deploy a new version of a script, keeping its history. Send the whole content; an empty summary or description keeps the current one.
     */
    export async function main(
      path: DynSelect_path,
      content: string,
      summary: string | undefined,
      description: string | undefined
    ) {
      const workspace = wmill.getWorkspace()
      const current = await wmill.ScriptService.getScriptByPath({ workspace, path })
      return await wmill.ScriptService.updateScript({
        workspace,
        path,
        requestBody: {
          path,
          language: current.language,
          content,
          summary: summary || current.summary,
          description: description || current.description,
        },
      })
    }
    

    Submitted by hugo989 5 hours ago