Create reaction for a team discussion comment

Create a reaction to a [team discussion comment](https://docs.

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 a team discussion comment
6
 * Create a reaction to a [team discussion comment](https://docs.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  team_slug: string,
12
  discussion_number: string,
13
  comment_number: string,
14
  body: {
15
    content:
16
      | "+1"
17
      | "-1"
18
      | "laugh"
19
      | "confused"
20
      | "heart"
21
      | "hooray"
22
      | "rocket"
23
      | "eyes";
24
    [k: string]: unknown;
25
  }
26
) {
27
  const url = new URL(
28
    `https://api.github.com/orgs/${org}/teams/${team_slug}/discussions/${discussion_number}/comments/${comment_number}/reactions`
29
  );
30

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