Merge a pull request
One script reply has been approved by the moderators Verified

This endpoint triggers [notifications](https://docs.

Created by hugo697 810 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 250 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Merge 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
    commit_message?: string;
15
    commit_title?: string;
16
    merge_method?: "merge" | "squash" | "rebase";
17
    sha?: string;
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}/merge`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39