0

Create Pull Request Review

by
Published today

Approve, request changes on, or comment on a pull request. REQUEST_CHANGES and COMMENT need a body.

Script github Verified

The script

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

3
/**
4
 * Create Pull Request Review
5
 * Approve, request changes on, or comment on a pull request. REQUEST_CHANGES and COMMENT need a body.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  pull_number: number,
12
  event: "APPROVE" | "REQUEST_CHANGES" | "COMMENT",
13
  body: string | undefined,
14
  commit_id: string | undefined
15
) {
16
  const response = await fetch(
17
    `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}/reviews`,
18
    {
19
      method: "POST",
20
      headers: {
21
        Authorization: `Bearer ${auth.token}`,
22
        "Content-Type": "application/json",
23
        Accept: "application/vnd.github+json",
24
        "X-GitHub-Api-Version": "2022-11-28",
25
      },
26
      body: JSON.stringify({ event, body, commit_id }),
27
    }
28
  )
29

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

34
  return await response.json()
35
}
36