Get a workflow run attempt

Gets a specific workflow run attempt. Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the `repo` scope. GitHub Apps must have the `actions:read` permission to use this endpoint.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get a workflow run attempt
6
 * Gets a specific workflow run attempt. Anyone with read access to the repository
7
can use this endpoint. If the repository is private you must use an access token
8
with the `repo` scope. GitHub Apps must have the `actions:read` permission to
9
use this endpoint.
10
 */
11
export async function main(
12
  auth: Github,
13
  owner: string,
14
  repo: string,
15
  run_id: string,
16
  attempt_number: string,
17
  exclude_pull_requests: string | undefined
18
) {
19
  const url = new URL(
20
    `https://api.github.com/repos/${owner}/${repo}/actions/runs/${run_id}/attempts/${attempt_number}`
21
  );
22
  for (const [k, v] of [["exclude_pull_requests", exclude_pull_requests]]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40