export type BranchProtectionRule = {pattern: string}; export type CreateApiRepositoriesRepositoryBranchProtectionArgs = {body: BranchProtectionRule}; export type CreateApiRepositoriesRepositoryBranchProtectionOptions = {baseUrl: string, jwtToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /repositories/{repository}/branch_protection * * Also accepts auth: basic_auth, cookie_auth */ export const createApiRepositoriesRepositoryBranchProtection = async (args: CreateApiRepositoriesRepositoryBranchProtectionArgs, options: CreateApiRepositoriesRepositoryBranchProtectionOptions) => { const {baseUrl, fetch: fetchFn = fetch, jwtToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (jwtToken !== undefined) headers.set('authorization', `Bearer ${jwtToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/repositories/${encodeURIComponent(String(args.repository))}/branch_protection${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 undefined };