Create reaction for an issue comment

Create a reaction to an [issue comment](https://docs.github.com/rest/reference/issues#comments). A response with an HTTP `200` status means that you already added the reaction type to this issue comment.

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
 * Create reaction for an issue comment
6
 * Create a reaction to an [issue comment](https://docs.github.com/rest/reference/issues#comments). A response with an HTTP `200` status means that you already added the reaction type to this issue comment.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  comment_id: string,
13
  body: {
14
    content:
15
      | "+1"
16
      | "-1"
17
      | "laugh"
18
      | "confused"
19
      | "heart"
20
      | "hooray"
21
      | "rocket"
22
      | "eyes";
23
    [k: string]: unknown;
24
  }
25
) {
26
  const url = new URL(
27
    `https://api.github.com/repos/${owner}/${repo}/issues/comments/${comment_id}/reactions`
28
  );
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44