0

Update Pull Request

by
Published today

Update a pull request's title, body, state or base branch. Only the fields you set change.

Script github Verified

The script

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

3
/**
4
 * Update Pull Request
5
 * Update a pull request's title, body, state or base branch. Only the fields you set change.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  pull_number: number,
12
  title: string | undefined,
13
  body: string | undefined,
14
  state: "open" | "closed" | undefined,
15
  base: string | undefined,
16
  maintainer_can_modify: boolean | undefined
17
) {
18
  const response = await fetch(
19
    `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}`,
20
    {
21
      method: "PATCH",
22
      headers: {
23
        Authorization: `Bearer ${auth.token}`,
24
        "Content-Type": "application/json",
25
        Accept: "application/vnd.github+json",
26
        "X-GitHub-Api-Version": "2022-11-28",
27
      },
28
      body: JSON.stringify({ title, body, state, base, maintainer_can_modify }),
29
    }
30
  )
31

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

36
  return await response.json()
37
}
38