0

Create Pull Request

by
Published today

Open a pull request merging head into base. For a cross-repository PR, set head to 'username:branch'.

Script github Verified

The script

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

3
/**
4
 * Create Pull Request
5
 * Open a pull request merging head into base. For a cross-repository PR, set head to 'username:branch'.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  title: string,
12
  head: string,
13
  base: string,
14
  body: string | undefined,
15
  draft: boolean = false,
16
  maintainer_can_modify: boolean | undefined
17
) {
18
  const response = await fetch(
19
    `https://api.github.com/repos/${owner}/${repo}/pulls`,
20
    {
21
      method: "POST",
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({
29
        title,
30
        head,
31
        base,
32
        body,
33
        draft,
34
        maintainer_can_modify,
35
      }),
36
    }
37
  )
38

39
  if (!response.ok) {
40
    throw new Error(`${response.status} ${await response.text()}`)
41
  }
42

43
  return await response.json()
44
}
45