type Github = {
token: string;
};
/**
* Create a repository webhook
* Repositories can have multiple webhooks installed. Each webhook should have a unique `config`. Multiple webhooks can
share the same `config` as long as those webhooks do not have any `events` that overlap.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
active?: boolean;
config?: {
content_type?: string;
digest?: string;
insecure_ssl?: string | number;
secret?: string;
token?: string;
url?: string;
[k: string]: unknown;
};
events?: string[];
name?: string;
}
) {
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/hooks`);
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 367 days ago
type Github = {
token: string;
};
/**
* Create a repository webhook
* Repositories can have multiple webhooks installed. Each webhook should have a unique `config`. Multiple webhooks can
share the same `config` as long as those webhooks do not have any `events` that overlap.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
active?: boolean;
config?: {
content_type?: string;
digest?: string;
insecure_ssl?: string | number;
secret?: string;
token?: string;
url?: string;
[k: string]: unknown;
};
events?: string[];
name?: string;
}
) {
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/hooks`);
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 927 days ago