Edits history of script submission #11010 for ' Rollback App (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Rollback App
     * Rollback an app to a previous deployment. A new deployment will be created to perform the rollback.
    The app will be pinned to the rollback deployment preventing any new deployments from being created,
    either manually or through Auto Deploy on Push webhooks. To resume deployments, the rollback must be
    either committed or reverted.
    
    It is recommended to use the Validate App Rollback endpoint to double check if the rollback is
    valid and if there are any warnings.
    
     */
    export async function main(
      auth: Digitalocean,
      app_id: string,
      body: { deployment_id?: string; skip_pin?: false | true },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/apps/${app_id}/rollback`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 537 days ago