export type BranchProtectionRule = {pattern: string}; export type UpdateApiRepositoriesRepositorySettingsBranchProtectionArgs = {'If-Match'?: string | undefined, body: Array}; export type UpdateApiRepositoriesRepositorySettingsBranchProtectionOptions = {baseUrl: string, jwtToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * PUT /repositories/{repository}/settings/branch_protection * * Also accepts auth: basic_auth, cookie_auth */ export const updateApiRepositoriesRepositorySettingsBranchProtection = async (args: UpdateApiRepositoriesRepositorySettingsBranchProtectionArgs, options: UpdateApiRepositoriesRepositorySettingsBranchProtectionOptions) => { const {baseUrl, fetch: fetchFn = fetch, jwtToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['If-Match'] != null) headers.set("If-Match", String(args['If-Match'])) if (jwtToken !== undefined) headers.set('authorization', `Bearer ${jwtToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/repositories/${encodeURIComponent(String(args.repository))}/settings/branch_protection${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };