0

Get Reviewers

by
Published today

Get a pull request's pending review requests (users and teams) and the reviews already submitted.

Script github Verified

The script

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

3
/**
4
 * Get Reviewers
5
 * Get a pull request's pending review requests (users and teams) and the reviews already submitted.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  pull_number: number
12
) {
13
  const base = `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}`
14
  const get = async (path: string) => {
15
    const response = await fetch(`${base}/${path}`, {
16
      headers: {
17
        Authorization: `Bearer ${auth.token}`,
18
        Accept: "application/vnd.github+json",
19
        "X-GitHub-Api-Version": "2022-11-28",
20
      },
21
    })
22
    if (!response.ok) {
23
      throw new Error(`${response.status} ${await response.text()}`)
24
    }
25
    return await response.json()
26
  }
27

28
  // ponytail: first 100 reviews only; page reviews if a PR ever has more
29
  const [requested, reviews] = await Promise.all([
30
    get("requested_reviewers"),
31
    get("reviews?per_page=100"),
32
  ])
33
  return { requested, reviews }
34
}
35