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