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

Draft pull requests are available in public repositories with GitHub Free and GitHub Free for organizations, GitHub Pro, and legacy per-repository billing plans, and in public and private repositories with GitHub Team and GitHub Enterprise Cloud.

Created by hugo697 173 days ago Viewed 3744 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 173 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Create a pull request
6
 * Draft pull requests are available in public repositories with GitHub Free and GitHub Free for organizations, GitHub Pro, and legacy per-repository billing plans, and in public and private repositories with GitHub Team and GitHub Enterprise Cloud.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  body: {
13
    base: string;
14
    body?: string;
15
    draft?: boolean;
16
    head: string;
17
    head_repo?: string;
18
    issue?: number;
19
    maintainer_can_modify?: boolean;
20
    title?: string;
21
    [k: string]: unknown;
22
  }
23
) {
24
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/pulls`);
25

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