Edits history of script submission #10948 for ' Retrieve Active Deployment Logs (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Retrieve Active Deployment Logs
     * Retrieve the logs of the active deployment if one exists. The response will include links to either real-time logs of an in-progress or active deployment or archived logs of a past deployment. Note log_type=BUILD logs will return logs associated with the current active deployment (being served). To view build logs associated with in-progress build, the query must explicitly reference the deployment id.
     */
    export async function main(
      auth: Digitalocean,
      app_id: string,
      component_name: 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}/components/${component_name}/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