0

Retrieve Active Deployment Aggregate Logs

by
Published Dec 20, 2024

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.

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