List check suites for a Git reference

**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 suites for a Git reference
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
  ref: string,
13
  app_id: string | undefined,
14
  check_name: string | undefined,
15
  per_page: string | undefined,
16
  page: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/commits/${ref}/check-suites`
20
  );
21
  for (const [k, v] of [
22
    ["app_id", app_id],
23
    ["check_name", check_name],
24
    ["per_page", per_page],
25
    ["page", page],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44