0

Retrieve Deployment Logs

by
Published Dec 20, 2024

Retrieve the logs of a past, in-progress, or active deployment. 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 Deployment Logs
7
 * Retrieve the logs of a past, in-progress, or active deployment. 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
  component_name: string,
14
  follow: string | undefined,
15
  type:
16
    | "UNSPECIFIED"
17
    | "BUILD"
18
    | "DEPLOY"
19
    | "RUN"
20
    | "RUN_RESTARTED"
21
    | undefined,
22
  pod_connection_timeout: string | undefined,
23
) {
24
  const url = new URL(
25
    `https://api.digitalocean.com/v2/apps/${app_id}/deployments/${deployment_id}/components/${component_name}/logs`,
26
  );
27
  for (const [k, v] of [
28
    ["follow", follow],
29
    ["type", type],
30
    ["pod_connection_timeout", pod_connection_timeout],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49