type Github = {
token: string;
};
/**
* Create a pull request
* 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.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
base: string;
body?: string;
draft?: boolean;
head: string;
head_repo?: string;
issue?: number;
maintainer_can_modify?: boolean;
title?: string;
[k: string]: unknown;
}
) {
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/pulls`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 407 days ago