List discussion comments (Legacy)

**Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new [List discussion comments](https://docs.github.com/rest/reference/teams#list-discussion-comments) endpoint. List all comments on a team discussion. OAuth access tokens require the `read:discussion` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/).

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 discussion comments (Legacy)
6
 * **Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new [List discussion comments](https://docs.github.com/rest/reference/teams#list-discussion-comments) endpoint.
7

8
List all comments on a team discussion. OAuth access tokens require the `read:discussion` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/).
9
 */
10
export async function main(
11
  auth: Github,
12
  team_id: string,
13
  discussion_number: string,
14
  direction: "asc" | "desc" | undefined,
15
  per_page: string | undefined,
16
  page: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.github.com/teams/${team_id}/discussions/${discussion_number}/comments`
20
  );
21
  for (const [k, v] of [
22
    ["direction", direction],
23
    ["per_page", per_page],
24
    ["page", page],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43