import {z} from 'zod' export type CreateApiApiProjectsProjectIdBranchesBranchIdMergeArgs = {projectId: string, branchId: string | 'main', body: {message: string, resolutions?: (Array<{path: string, resolution: 'useLeft' | 'useRight' | 'manual', content: unknown, hash?: string | undefined}>) | undefined} | null}; export type CreateApiApiProjectsProjectIdBranchesBranchIdMergeOptions = {baseUrl: string, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiProjectsProjectIdBranchesBranchIdMergeResponse = z.object({success: z.boolean(), requiresApproval: z.boolean(), changeRequestId: z.string().optional(), mergeCommitId: z.string().optional(), message: z.string(), changes: z.array(z.object({type: z.enum(["added", "deleted", "modified", "renamed"]), file: z.unknown(), from: z.unknown(), to: z.unknown()})).optional(), stats: z.object({filesAdded: z.number(), filesDeleted: z.number(), filesModified: z.number(), filesRenamed: z.number().optional(), totalChanges: z.number()}).optional()}); 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 }; /** * Merge branch * * POST /api/projects/{projectId}/branches/{branchId}/merge * * Also accepts auth: internalAuth */ export const createApiApiProjectsProjectIdBranchesBranchIdMerge = async (args: CreateApiApiProjectsProjectIdBranchesBranchIdMergeArgs, options: CreateApiApiProjectsProjectIdBranchesBranchIdMergeOptions) => { const {baseUrl, fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.projectId))}/branches/${encodeURIComponent(String(args.branchId))}/merge${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 validateResponse(createApiApiProjectsProjectIdBranchesBranchIdMergeResponse, await res.json()) };