import {z} from 'zod' export type GetApiSettingsLogicalRepositoriesIdArgs = {id: number}; export type GetApiSettingsLogicalRepositoriesIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const repositoryID = z.string(); export const logicalPRRules = z.object({title: z.string().optional(), labels_include: z.array(z.string()).optional()}); export const releaseMatchStrategy = z.enum(["branch", "event", "tag", "tag_or_branch"]); export const releaseMatchSetting = z.object({branches: z.string(), tags: z.string(), events: z.string().optional(), match: releaseMatchStrategy, default_branch: z.string().optional()}); export const logicalDeploymentRules = z.object({title: z.string().optional(), labels_include: z.record(z.string(), z.array(z.string())).optional()}); export const logicalRepository = z.object({name: z.string().max(100), parent: repositoryID, prs: logicalPRRules, releases: releaseMatchSetting, deployments: logicalDeploymentRules.optional()}); export const logicalRepositories = z.array(logicalRepository); 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 the currently configured logical repositories. * A logical repository is a set of rules to match PRs, releases, and deployments * that has a name and pretends to be a regular GitHub repository everywhere in UI * and API requests. * This feature is particularly useful to reap monorepos into separate, joint or disjoint * parts. * * * GET /settings/logical_repositories/{id} * * Also accepts auth: apiKeyAuth */ export const getApiSettingsLogicalRepositoriesId = async (args: GetApiSettingsLogicalRepositoriesIdArgs, options: GetApiSettingsLogicalRepositoriesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/settings/logical_repositories/${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(logicalRepositories, await res.json()) };