List reactions for a release

List the reactions to a [release](https://docs.github.com/rest/reference/repos#releases).

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List reactions for a release
6
 * List the reactions to a [release](https://docs.github.com/rest/reference/repos#releases).
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  release_id: string,
13
  content: "+1" | "laugh" | "heart" | "hooray" | "rocket" | "eyes" | undefined,
14
  per_page: string | undefined,
15
  page: string | undefined
16
) {
17
  const url = new URL(
18
    `https://api.github.com/repos/${owner}/${repo}/releases/${release_id}/reactions`
19
  );
20
  for (const [k, v] of [
21
    ["content", content],
22
    ["per_page", per_page],
23
    ["page", page],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42