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