1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * List workflow runs for a repository |
6 | * Lists all workflow runs for a repository. You can use parameters to narrow the list of results. For more information about using parameters, see [Parameters](https://docs.github.com/rest/overview/resources-in-the-rest-api#parameters). |
7 |
|
8 | 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. |
9 | */ |
10 | export async function main( |
11 | auth: Github, |
12 | owner: string, |
13 | repo: string, |
14 | actor: string | undefined, |
15 | branch: string | undefined, |
16 | event: string | undefined, |
17 | status: |
18 | | "completed" |
19 | | "action_required" |
20 | | "cancelled" |
21 | | "failure" |
22 | | "neutral" |
23 | | "skipped" |
24 | | "stale" |
25 | | "success" |
26 | | "timed_out" |
27 | | "in_progress" |
28 | | "queued" |
29 | | "requested" |
30 | | "waiting" |
31 | | "pending" |
32 | | undefined, |
33 | per_page: string | undefined, |
34 | page: string | undefined, |
35 | created: string | undefined, |
36 | exclude_pull_requests: string | undefined, |
37 | check_suite_id: string | undefined, |
38 | head_sha: string | undefined |
39 | ) { |
40 | const url = new URL( |
41 | `https://api.github.com/repos/${owner}/${repo}/actions/runs` |
42 | ); |
43 | for (const [k, v] of [ |
44 | ["actor", actor], |
45 | ["branch", branch], |
46 | ["event", event], |
47 | ["status", status], |
48 | ["per_page", per_page], |
49 | ["page", page], |
50 | ["created", created], |
51 | ["exclude_pull_requests", exclude_pull_requests], |
52 | ["check_suite_id", check_suite_id], |
53 | ["head_sha", head_sha], |
54 | ]) { |
55 | if (v !== undefined && v !== "") { |
56 | url.searchParams.append(k, v); |
57 | } |
58 | } |
59 | const response = await fetch(url, { |
60 | method: "GET", |
61 | headers: { |
62 | Authorization: "Bearer " + auth.token, |
63 | }, |
64 | body: undefined, |
65 | }); |
66 | if (!response.ok) { |
67 | const text = await response.text(); |
68 | throw new Error(`${response.status} ${text}`); |
69 | } |
70 | return await response.json(); |
71 | } |
72 |
|