import {z} from 'zod' export type GetApiApiBuildsIdMavenBuildCachePerformanceOptions = {baseUrl?: string | undefined, DevelocityAccessKeyOrToken?: string | undefined, fetch?: typeof fetch | undefined}; export const mavenBuildCachePerformanceGoalExecutionEntry = z.object({goalName: z.string(), mojoType: z.string(), goalExecutionId: z.string(), goalProjectName: z.string(), avoidanceOutcome: z.enum(["avoided_from_local_cache", "avoided_from_remote_cache", "executed_cacheable", "executed_not_cacheable", "executed_unknown_cacheability", "skipped"]), duration: z.number().int(), fingerprintingDuration: z.number().int().nullable().optional(), avoidanceSavings: z.number().int().nullable().optional(), nonCacheabilityCategory: z.enum(["build_cache_disabled_by_user", "goal_execution_marked_non_cacheable", "goal_not_supported", "no_gradle_enterprise_server_configured", "no_develocity_server_configured", "non_clean_build", "not_entitled", "offline_build", "unknown", "unknown_entitlements"]).nullable().optional(), nonCacheabilityReason: z.string().nullable().optional(), cacheArtifactSize: z.number().int().nullable().optional(), cacheArtifactRejectedReason: z.literal("artifact_size_too_large").nullable().optional(), cacheKey: z.string().nullable().optional(), hasFailed: z.boolean()}); export const mavenBuildCachePerformanceGoalExecution = z.array(mavenBuildCachePerformanceGoalExecutionEntry); export const mavenBuildCachePerformanceGoalFingerprintingSummary = z.object({count: z.number().int(), serialDuration: z.number().int()}); export const mavenBuildCachePerformanceAvoidanceSavingsSummary = z.object({total: z.number().int(), ratio: z.number(), localBuildCache: z.number().int(), remoteBuildCache: z.number().int()}); export const mavenBuildCachePerformanceBuildCacheLocalInfo = z.object({isEnabled: z.boolean(), isPushEnabled: z.boolean().nullable().optional(), isDisabledDueToError: z.boolean().optional(), directory: z.string().nullable().optional()}).nullable(); export const mavenBuildCachePerformanceBuildCacheRemoteInfo = z.object({isEnabled: z.boolean(), isPushEnabled: z.boolean().nullable().optional(), isDisabledDueToError: z.boolean().optional(), url: z.string().nullable().optional()}).nullable(); export const mavenBuildCachePerformanceBuildCacheOverhead = z.object({uploading: z.number().int(), downloading: z.number().int(), packing: z.number().int(), unpacking: z.number().int()}); export const mavenBuildCachePerformanceBuildCaches = z.object({local: mavenBuildCachePerformanceBuildCacheLocalInfo.optional(), remote: mavenBuildCachePerformanceBuildCacheRemoteInfo.optional(), overhead: mavenBuildCachePerformanceBuildCacheOverhead}).nullable(); export const mavenBuildCachePerformance = z.object({id: z.string(), buildTime: z.number().int(), effectiveProjectExecutionTime: z.number().int(), serialProjectExecutionTime: z.number().int(), serializationFactor: z.number(), goalExecution: mavenBuildCachePerformanceGoalExecution, goalFingerprintingSummary: mavenBuildCachePerformanceGoalFingerprintingSummary, avoidanceSavingsSummary: mavenBuildCachePerformanceAvoidanceSavingsSummary, buildCaches: mavenBuildCachePerformanceBuildCaches.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 build cache performance of a Maven build. * * GET /api/builds/{id}/maven-build-cache-performance */ export const getApiApiBuildsIdMavenBuildCachePerformance = async (options?: GetApiApiBuildsIdMavenBuildCachePerformanceOptions) => { 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))}/maven-build-cache-performance${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(mavenBuildCachePerformance, await res.json()) };