0

List Workflows

by
Published 4 days ago

List the GitHub Actions workflows of a repository.

Script github Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 days ago
1
//native
2

3
/**
4
 * List Workflows
5
 * List the GitHub Actions workflows of a repository.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  per_page: number = 30,
12
  page: number = 1
13
) {
14
  const url = new URL(
15
    `https://api.github.com/repos/${owner}/${repo}/actions/workflows`
16
  )
17
  for (const [k, v] of Object.entries({ per_page, page })) {
18
    if (v != null) url.searchParams.append(k, String(v))
19
  }
20

21
  const response = await fetch(url, {
22
    headers: {
23
      Authorization: `Bearer ${auth.token}`,
24
      Accept: "application/vnd.github+json",
25
      "X-GitHub-Api-Version": "2022-11-28",
26
    },
27
  })
28

29
  if (!response.ok) {
30
    throw new Error(`${response.status} ${await response.text()}`)
31
  }
32

33
  return await response.json()
34
}
35