0

List Repository Labels

by
Published 4 days ago

List the labels defined in a repository. Paginate with page.

Script github Verified

The script

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

3
/**
4
 * List Repository Labels
5
 * List the labels defined in a repository. Paginate with page.
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(`https://api.github.com/repos/${owner}/${repo}/labels`)
15
  for (const [k, v] of Object.entries({ per_page, page })) {
16
    if (v != null) url.searchParams.append(k, String(v))
17
  }
18

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

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

31
  return await response.json()
32
}
33