0

Retrieve Aggregate Deployment Logs

by
Published Dec 20, 2024

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.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retrieve Aggregate Deployment Logs
7
 * 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.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  app_id: string,
12
  deployment_id: string,
13
  follow: string | undefined,
14
  type:
15
    | "UNSPECIFIED"
16
    | "BUILD"
17
    | "DEPLOY"
18
    | "RUN"
19
    | "RUN_RESTARTED"
20
    | undefined,
21
  pod_connection_timeout: string | undefined,
22
) {
23
  const url = new URL(
24
    `https://api.digitalocean.com/v2/apps/${app_id}/deployments/${deployment_id}/logs`,
25
  );
26
  for (const [k, v] of [
27
    ["follow", follow],
28
    ["type", type],
29
    ["pod_connection_timeout", pod_connection_timeout],
30
  ]) {
31
    if (v !== undefined && v !== "" && k !== undefined) {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48