import {z} from 'zod' export type GetApiServiceOwnerUsernameReposRepoNameTestResultsIdArgs = {branch?: string | undefined, commit_id?: string | undefined, duration_max?: number | undefined, duration_min?: number | undefined, id: string, outcome?: string | undefined, owner_username: string, repo_name: string, service: string}; export type GetApiServiceOwnerUsernameReposRepoNameTestResultsIdOptions = {baseUrl?: string | undefined, tokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const testrun = z.object({test_id: z.string(), name: z.string().nullable(), classname: z.string().nullable(), testsuite: z.string().nullable(), computed_name: z.string().nullable(), outcome: z.string(), duration_seconds: z.number().nullable(), failure_message: z.string().nullable(), framework: z.string().nullable(), filename: z.string().nullable(), repo_id: z.number().int(), commit_sha: z.string().nullable(), branch: z.string().nullable(), flags: z.array(z.string()).nullable(), upload_id: z.number().int().nullable(), properties: z.unknown(), timestamp: z.string()}); 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 }; /** * Retrieve test results * * GET /{service}/{owner_username}/repos/{repo_name}/test-results/{id}/ */ export const getApiServiceOwnerUsernameReposRepoNameTestResultsId = async (args: GetApiServiceOwnerUsernameReposRepoNameTestResultsIdArgs, options?: GetApiServiceOwnerUsernameReposRepoNameTestResultsIdOptions) => { const {baseUrl = "https://api.codecov.io/api/v2", fetch: fetchFn = fetch, tokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.branch != null) query.append("branch", String(args.branch)) if (args.commit_id != null) query.append("commit_id", String(args.commit_id)) if (args.duration_max != null) query.append("duration_max", String(args.duration_max)) if (args.duration_min != null) query.append("duration_min", String(args.duration_min)) if (args.outcome != null) query.append("outcome", String(args.outcome)) if (tokenAuth !== undefined) headers.set('authorization', `Bearer ${tokenAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.service))}/${encodeURIComponent(String(args.owner_username))}/repos/${encodeURIComponent(String(args.repo_name))}/test-results/${encodeURIComponent(String(args.id))}/${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(testrun, await res.json()) };