import {z} from 'zod' export type DeleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsArgs = {owner: string, repo: string, branch: string, body: {apps: Array}}; export type DeleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const simpleUser = z.object({name: z.string().nullable().optional(), email: z.string().nullable().optional(), login: z.string(), id: z.number().int(), node_id: z.string(), avatar_url: z.string(), gravatar_id: z.string().nullable(), url: z.string(), html_url: z.string(), followers_url: z.string(), following_url: z.string(), gists_url: z.string(), starred_url: z.string(), subscriptions_url: z.string(), organizations_url: z.string(), repos_url: z.string(), events_url: z.string(), received_events_url: z.string(), type: z.string(), site_admin: z.boolean(), starred_at: z.string().optional(), user_view_type: z.string().optional()}); export const enterprise = z.object({description: z.string().nullable().optional(), html_url: z.string(), website_url: z.string().nullable().optional(), id: z.number().int(), node_id: z.string(), name: z.string(), slug: z.string(), created_at: z.string().nullable(), updated_at: z.string().nullable(), avatar_url: z.string()}); export const integration = z.object({id: z.number().int(), slug: z.string().optional(), node_id: z.string(), client_id: z.string().optional(), owner: z.union([simpleUser, enterprise]), name: z.string(), description: z.string().nullable(), external_url: z.string(), html_url: z.string(), created_at: z.string(), updated_at: z.string(), permissions: z.object({issues: z.string().optional(), checks: z.string().optional(), metadata: z.string().optional(), contents: z.string().optional(), deployments: z.string().optional()}).and(z.record(z.string(), z.string())), events: z.array(z.string()), installations_count: z.number().int().optional()}).nullable(); export const deleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsResponse = z.array(integration); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Remove app access restrictions * * DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps */ export const deleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsApps = async (args: DeleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsArgs, options?: DeleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsOptions) => { const {baseUrl = "https://api.github.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/repos/${encodeURIComponent(String(args.owner))}/${encodeURIComponent(String(args.repo))}/branches/${encodeURIComponent(String(args.branch))}/protection/restrictions/apps${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", 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 validateResponse(deleteApiReposOwnerRepoBranchesBranchProtectionRestrictionsAppsResponse, await res.json()) };