0

Create Issue Comment

by
Published 20 days ago

Comment on an issue or pull request (pull requests share the issue comment thread).

Script github Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 21 days ago
1
//native
2

3
/**
4
 * Create Issue Comment
5
 * Comment on an issue or pull request (pull requests share the issue comment thread).
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  issue_number: number,
12
  body: string
13
) {
14
  const response = await fetch(
15
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/comments`,
16
    {
17
      method: "POST",
18
      headers: {
19
        Authorization: `Bearer ${auth.token}`,
20
        "Content-Type": "application/json",
21
        Accept: "application/vnd.github+json",
22
        "X-GitHub-Api-Version": "2022-11-28",
23
      },
24
      body: JSON.stringify({ body }),
25
    }
26
  )
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34