import {z} from 'zod' export type GetApiApiBuildsIdGradleArtifactTransformExecutionsOptions = {baseUrl?: string | undefined, DevelocityAccessKeyOrToken?: string | undefined, fetch?: typeof fetch | undefined}; export const gradleArtifactTransformAttribute = z.object({name: z.string(), from: z.string(), to: z.string()}); export const gradleArtifactTransformExecutionEntry = z.object({artifactTransformExecutionName: z.string(), transformActionType: z.string(), inputArtifactName: z.string(), changedAttributes: z.array(gradleArtifactTransformAttribute), outcome: z.enum(["failed", "success", "from_cache", "up_to_date", "unknown", "skipped"]), avoidanceOutcome: z.enum(["avoided_up_to_date", "avoided_from_local_cache", "avoided_from_remote_cache", "executed_cacheable", "executed_not_cacheable", "executed_unknown_cacheability", "avoided_unknown_cachebility", "avoided_unknown_reason", "skipped"]), duration: z.number().int(), fingerprintingDuration: z.number().int().optional(), avoidanceSavings: z.number().int().optional(), nonCacheabilityCategory: z.enum(["build_cache_not_enabled", "disabled_to_ensure_correctness", "not_cacheable", "unknown"]).nullable().optional(), nonCacheabilityReason: z.string().nullable().optional(), cacheArtifactSize: z.number().int().nullable().optional(), cacheArtifactRejectedReason: z.literal("artifact_size_too_large").nullable().optional(), skipReasonMessage: z.string().nullable().optional(), cacheKey: z.string().nullable().optional()}); export const gradleArtifactTransformExecutions = z.object({artifactTransformExecutions: z.array(gradleArtifactTransformExecutionEntry).nullable().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 }; /** * Get the artifact transform execution list of a Gradle build. * * GET /api/builds/{id}/gradle-artifact-transform-executions */ export const getApiApiBuildsIdGradleArtifactTransformExecutions = async (options?: GetApiApiBuildsIdGradleArtifactTransformExecutionsOptions) => { const {baseUrl = "https://develocity.example.com", fetch: fetchFn = fetch, DevelocityAccessKeyOrToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (DevelocityAccessKeyOrToken !== undefined) headers.set('authorization', `Bearer ${DevelocityAccessKeyOrToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/builds/${encodeURIComponent(String(args.id))}/gradle-artifact-transform-executions${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(gradleArtifactTransformExecutions, await res.json()) };