0

Create Pull Request Review

by
Published 20 days ago

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 20 days 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({
27
        event,
28
        body: body || undefined,
29
        commit_id: commit_id || undefined,
30
      }),
31
    }
32
  )
33

34
  if (!response.ok) {
35
    throw new Error(`${response.status} ${await response.text()}`)
36
  }
37

38
  return await response.json()
39
}
40