List reactions for an issue

List the reactions to an [issue](https://docs.github.com/rest/reference/issues).

Script github Verified

by hugo697 ยท 10/25/2023

The script

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