0
List releases
One script reply has been approved by the moderators Verified

This returns a list of releases, which does not include regular Git tags that have not been associated with a release. To get a list of Git tags, use the Repository Tags API.

Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.

Created by hugo697 407 days ago Viewed 9021 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 407 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List releases
6
 * This returns a list of releases, which does not include regular Git tags that have not been associated with a release. To get a list of Git tags, use the [Repository Tags API](https://docs.github.com/rest/reference/repos#list-repository-tags).
7

8
Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  per_page: string | undefined,
15
  page: string | undefined
16
) {
17
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/releases`);
18
  for (const [k, v] of [
19
    ["per_page", per_page],
20
    ["page", page],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39