0

List Releases

by
Published today

List a repository's releases, newest first. Draft releases only appear with push access. Paginate with page.

Script github Verified

The script

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

3
/**
4
 * List Releases
5
 * List a repository's releases, newest first. Draft releases only appear with push access. 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}/releases`)
15
  url.searchParams.append("per_page", String(per_page))
16
  url.searchParams.append("page", String(page))
17

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

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

30
  return await response.json()
31
}
32