import {z} from 'zod' export type QuarantineSource = 'manual' | 'auto'; export type HealthStatus = 'healthy' | 'flaky' | 'broken'; export type QuarantinesSort = 'created_at' | 'test_name' | 'pipeline_name' | 'job_name' | 'health_status' | 'source'; export type GetApiCiOwnerRepositoriesRepositoryQuarantinesArgs = {repository: string, owner: string, branch?: (string | null) | undefined, test_id?: (Array | null) | undefined, source?: (Array | null) | undefined, branch_name?: (Array | null) | undefined, branch_name_exclude?: (Array | null) | undefined, pipeline_name?: (Array | null) | undefined, pipeline_name_exclude?: (Array | null) | undefined, job_name?: (Array | null) | undefined, job_name_exclude?: (Array | null) | undefined, test_name?: (Array | null) | undefined, test_name_exclude?: (Array | null) | undefined, health_status?: (Array | null) | undefined, health_status_exclude?: (Array | null) | undefined, cursor?: (string | null) | undefined, per_page?: (number | null) | undefined, sort?: QuarantinesSort | undefined, direction?: ('asc' | 'desc') | undefined}; export type GetApiCiOwnerRepositoriesRepositoryQuarantinesOptions = {baseUrl: string, AdminApplicationKey?: string | undefined, fetch?: typeof fetch | undefined}; export const quarantineSource = z.enum(["manual", "auto"]); export const healthStatus = z.enum(["healthy", "flaky", "broken"]); export const quarantinedTest = z.object({id: z.string(), test_name: z.string(), test_id: z.string(), reason: z.string(), issue_url: z.string().nullable(), branch: z.string().nullable(), branch_name: z.string().nullable(), pipeline_name: z.string().nullable(), job_name: z.string().nullable(), created_at: z.string(), source: quarantineSource.optional(), health_status: healthStatus.nullable(), is_recovered: z.boolean(), unquarantine_when_healthy: z.boolean()}); export const quarantinedTestsResponse = z.object({size: z.number().int(), per_page: z.number().int().nullable(), quarantined_tests: z.array(quarantinedTest), total: z.number().int()}); 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 }; /** * List quarantined tests * * GET /ci/{owner}/repositories/{repository}/quarantines * * Also accepts auth: CIApplicationKey, MergifyTokenBearerAuth, GitHubTokenBearerAuth */ export const getApiCiOwnerRepositoriesRepositoryQuarantines = async (args: GetApiCiOwnerRepositoriesRepositoryQuarantinesArgs, options: GetApiCiOwnerRepositoriesRepositoryQuarantinesOptions) => { const {baseUrl, fetch: fetchFn = fetch, AdminApplicationKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.branch != null) query.append("branch", String(args.branch)) for (const item of args.test_id ?? []) query.append("test_id", String(item)) for (const item of args.source ?? []) query.append("source", String(item)) for (const item of args.branch_name ?? []) query.append("branch_name", String(item)) for (const item of args.branch_name_exclude ?? []) query.append("branch_name_exclude", String(item)) for (const item of args.pipeline_name ?? []) query.append("pipeline_name", String(item)) for (const item of args.pipeline_name_exclude ?? []) query.append("pipeline_name_exclude", String(item)) for (const item of args.job_name ?? []) query.append("job_name", String(item)) for (const item of args.job_name_exclude ?? []) query.append("job_name_exclude", String(item)) for (const item of args.test_name ?? []) query.append("test_name", String(item)) for (const item of args.test_name_exclude ?? []) query.append("test_name_exclude", String(item)) for (const item of args.health_status ?? []) query.append("health_status", String(item)) for (const item of args.health_status_exclude ?? []) query.append("health_status_exclude", String(item)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.direction != null) query.append("direction", String(args.direction)) if (AdminApplicationKey !== undefined) headers.set('authorization', `Bearer ${AdminApplicationKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ci/${encodeURIComponent(String(args.owner))}/repositories/${encodeURIComponent(String(args.repository))}/quarantines${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(quarantinedTestsResponse, await res.json()) };