import {z} from 'zod' export type GetApiApiBuildsIdGradleAttributesOptions = {baseUrl?: string | undefined, DevelocityAccessKeyOrToken?: string | undefined, fetch?: typeof fetch | undefined}; export const buildAttributesValue = z.object({name: z.string(), value: z.string().optional()}); export const buildAttributesLink = z.object({label: z.string(), url: z.string()}); export const gradleDevelocitySettings = z.object({backgroundPublicationEnabled: z.boolean().nullable().optional(), buildOutputCapturingEnabled: z.boolean().nullable().optional(), fileFingerprintCapturingEnabled: z.boolean().nullable().optional(), testOutputCapturingEnabled: z.boolean().nullable().optional(), resourceUsageCapturingEnabled: z.boolean().nullable().optional(), taskInputsFileCapturingEnabled: z.boolean().nullable().optional()}); export const gradleBuildOptions = z.object({buildCacheEnabled: z.boolean().nullable().optional(), configurationCacheEnabled: z.boolean().nullable().optional(), configurationOnDemandEnabled: z.boolean(), continuousBuildEnabled: z.boolean(), continueOnFailureEnabled: z.boolean(), daemonEnabled: z.boolean(), dryRunEnabled: z.boolean(), excludedTasks: z.array(z.string()), fileSystemWatchingEnabled: z.boolean().nullable().optional(), isolatedProjectsEnabled: z.boolean().nullable().optional(), maxNumberOfGradleWorkers: z.number().int(), offlineModeEnabled: z.boolean(), parallelProjectExecutionEnabled: z.boolean(), refreshDependenciesEnabled: z.boolean(), rerunTasksEnabled: z.boolean()}); export const buildAttributesEnvironment = z.object({username: z.string().nullable().optional(), operatingSystem: z.string(), numberOfCpuCores: z.number().int(), jreVersion: z.string(), jvmVersion: z.string(), jvmMaxMemoryHeapSize: z.number().int(), jvmCharset: z.string().nullable().optional(), jvmLocale: z.string(), publicHostname: z.string().nullable().optional(), localHostname: z.string().nullable().optional(), localIpAddresses: z.array(z.string()).nullable().optional()}); export const gradleGradleEnterpriseSettings = z.object({backgroundPublicationEnabled: z.boolean().nullable().optional(), buildOutputCapturingEnabled: z.boolean().nullable().optional(), taskInputsFileCapturingEnabled: z.boolean().nullable().optional(), testOutputCapturingEnabled: z.boolean().nullable().optional(), resourceUsageCapturingEnabled: z.boolean().nullable().optional()}); export const gradleAttributes = z.object({id: z.string(), buildStartTime: z.number().int(), buildDuration: z.number().int(), gradleVersion: z.string(), pluginVersion: z.string(), rootProjectName: z.string().nullable().optional(), requestedTasks: z.array(z.string()), hasFailed: z.boolean(), hasVerificationFailure: z.boolean().optional(), hasNonVerificationFailure: z.boolean().optional(), tags: z.array(z.string()), values: z.array(buildAttributesValue), links: z.array(buildAttributesLink), develocitySettings: gradleDevelocitySettings, buildOptions: gradleBuildOptions, environment: buildAttributesEnvironment, gradleEnterpriseSettings: gradleGradleEnterpriseSettings}); 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 attributes of a Gradle build. * * GET /api/builds/{id}/gradle-attributes */ export const getApiApiBuildsIdGradleAttributes = async (options?: GetApiApiBuildsIdGradleAttributesOptions) => { 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-attributes${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(gradleAttributes, await res.json()) };