Edits history of script submission #10949 for ' Retrieve Aggregate Deployment Logs (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Retrieve Aggregate Deployment Logs
     * Retrieve the logs of a past, in-progress, or active deployment. If a component name is specified, the logs will be limited to only that component. The response will include links to either real-time logs of an in-progress or active deployment or archived logs of a past deployment.
     */
    export async function main(
      auth: Digitalocean,
      app_id: string,
      deployment_id: string,
      follow: string | undefined,
      type:
        | "UNSPECIFIED"
        | "BUILD"
        | "DEPLOY"
        | "RUN"
        | "RUN_RESTARTED"
        | undefined,
      pod_connection_timeout: string | undefined,
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/apps/${app_id}/deployments/${deployment_id}/logs`,
      );
      for (const [k, v] of [
        ["follow", follow],
        ["type", type],
        ["pod_connection_timeout", pod_connection_timeout],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago