export type CreateApiV2GitWebhookWebhookArgs = {webhook: string, branch?: string | undefined, restart?: ('true' | 'false') | undefined, body: {repository: {clone_url: string, html_url: string, owner: {id: number, login?: string | undefined, type?: string | undefined}}, ref: string, after?: string | undefined, deleted?: boolean | undefined} | {[key: string]: unknown}}; export type CreateApiV2GitWebhookWebhookOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Receive a Git provider push webhook * * POST /v2/git/webhook/{webhook} */ export const createApiV2GitWebhookWebhook = async (args: CreateApiV2GitWebhookWebhookArgs, options?: CreateApiV2GitWebhookWebhookOptions) => { const {baseUrl = "https://api.squarecloud.app", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (args.branch != null) query.append("branch", String(args.branch)) if (args.restart != null) query.append("restart", String(args.restart)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/git/webhook/${encodeURIComponent(String(args.webhook))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };