0

List Workflows

by
Published today

List the GitHub Actions workflows of a repository.

Script github Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour 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
  url.searchParams.append("per_page", String(per_page))
18
  url.searchParams.append("page", String(page))
19

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

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

32
  return await response.json()
33
}
34