0

Merge Pull Request

by
Published today

Merge a pull request with a merge commit, squash or rebase. Set sha to make the merge fail if the head moved.

Script github Verified

The script

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

3
/**
4
 * Merge Pull Request
5
 * Merge a pull request with a merge commit, squash or rebase. Set sha to make the merge fail if the head moved.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  pull_number: number,
12
  merge_method: "merge" | "squash" | "rebase" | undefined,
13
  commit_title: string | undefined,
14
  commit_message: string | undefined,
15
  sha: string | undefined
16
) {
17
  const response = await fetch(
18
    `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}/merge`,
19
    {
20
      method: "PUT",
21
      headers: {
22
        Authorization: `Bearer ${auth.token}`,
23
        "Content-Type": "application/json",
24
        Accept: "application/vnd.github+json",
25
        "X-GitHub-Api-Version": "2022-11-28",
26
      },
27
      body: JSON.stringify({ merge_method, commit_title, commit_message, sha }),
28
    }
29
  )
30

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

35
  return await response.json()
36
}
37