List check runs in a check suite

**Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created.

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
 * List check runs in a check suite
6
 * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  check_suite_id: string,
13
  check_name: string | undefined,
14
  status: "queued" | "in_progress" | "completed" | undefined,
15
  filter: "latest" | "all" | undefined,
16
  per_page: string | undefined,
17
  page: string | undefined
18
) {
19
  const url = new URL(
20
    `https://api.github.com/repos/${owner}/${repo}/check-suites/${check_suite_id}/check-runs`
21
  );
22
  for (const [k, v] of [
23
    ["check_name", check_name],
24
    ["status", status],
25
    ["filter", filter],
26
    ["per_page", per_page],
27
    ["page", page],
28
  ]) {
29
    if (v !== undefined && v !== "") {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46