Create a review for a pull request

This endpoint triggers [notifications](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 a review for a pull request
6
 * This endpoint triggers [notifications](https://docs.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  pull_number: string,
13
  body: {
14
    body?: string;
15
    comments?: {
16
      body: string;
17
      line?: number;
18
      path: string;
19
      position?: number;
20
      side?: string;
21
      start_line?: number;
22
      start_side?: string;
23
      [k: string]: unknown;
24
    }[];
25
    commit_id?: string;
26
    event?: "APPROVE" | "REQUEST_CHANGES" | "COMMENT";
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(
31
    `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}/reviews`
32
  );
33

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