import {z} from 'zod' export type GetApiReposOwnerRepositoryStatsMergeQueueChecksOutcomeArgs = {repository: string, owner: string, base_ref?: (Array | null) | undefined, queue_name?: (Array | null) | undefined, priority_rule_name?: (Array | null) | undefined, start_at?: (string | null) | undefined, end_at?: (string | null) | undefined}; export type GetApiReposOwnerRepositoryStatsMergeQueueChecksOutcomeOptions = {baseUrl: string, AdminApplicationKey?: string | undefined, fetch?: typeof fetch | undefined}; export const queueChecksOutcome = z.object({BASE_BRANCH_CHANGED: z.number().int().optional(), BASE_BRANCH_MISSING: z.number().int().optional(), BATCH_MAX_FAILURE_RESOLUTION_ATTEMPTS: z.number().int().optional(), BATCH_REBUILT: z.number().int().optional(), BATCH_SCOPES_CHANGED: z.number().int().optional(), BRANCH_UPDATE_FAILED: z.number().int().optional(), CHECKS_FAILED: z.number().int().optional(), CHECKS_INTERRUPTED: z.number().int().optional(), CHECKS_TIMEOUT: z.number().int().optional(), DROPPED_BY_BISECTION_ELIMINATION: z.number().int().optional(), CONFLICT_WITH_BASE_BRANCH: z.number().int().optional(), CONFLICT_WITH_PULL_AHEAD: z.number().int().optional(), DRAFT_PULL_REQUEST_CHANGED: z.number().int().optional(), BATCH_PULL_REQUEST_CLOSED: z.number().int().optional(), INCOMPATIBILITY_WITH_BRANCH_PROTECTIONS: z.number().int().optional(), MERGE_QUEUE_RESET: z.number().int().optional(), PR_AHEAD_DEQUEUED: z.number().int().optional(), BATCH_AHEAD_FAILED: z.number().int().optional(), BATCH_AHEAD_BRANCH_EDITED: z.number().int().optional(), BATCH_AHEAD_REBUILT: z.number().int().optional(), PR_CHECKS_STOPPED_BECAUSE_MERGE_QUEUE_PAUSE: z.number().int().optional(), PR_DEQUEUED: z.number().int().optional(), PR_DEQUEUED_FROM_PARTITION: z.number().int().optional(), PR_UNEXPECTEDLY_FAILED_TO_MERGE: z.number().int().optional(), PR_WITH_HIGHER_PRIORITY_QUEUED: z.number().int().optional(), PULL_REQUEST_UPDATED: z.number().int().optional(), QUEUE_RULE_MISSING: z.number().int().optional(), SPECULATIVE_CHECK_NUMBER_REDUCED: z.number().int().optional(), SUCCESS: z.number().int().optional(), PR_MANUALLY_MERGED: z.number().int().optional(), DRAFT_PULL_REQUEST_CREATION_FAILED: z.number().int().optional(), DRAFT_PULL_REQUEST_CREATION_BRANCH_NOT_INDEXED: z.number().int().optional(), CONFIGURATION_CHANGED: z.number().int().optional(), UNPROCESSABLE_PULL_REQUEST: z.number().int().optional(), PR_MANUALLY_DEQUEUED: z.number().int().optional(), STACK_PREDECESSOR_DEQUEUED: z.number().int().optional(), INTERMEDIATE_RESULTS_SKIPPED: z.number().int().optional(), CHECKS_RETRIED: z.number().int().optional(), SCHEDULED_FREEZE_STATUS_CHANGED: z.number().int().optional(), SCHEDULE_BLOCKED_AHEAD_YIELDED: z.number().int().optional(), BASE_REF_ALIGNMENT_TIMEOUT: z.number().int().optional(), GITHUB_STACKED_PULL_REQUEST_MERGE_UNSUPPORTED: z.number().int().optional(), GITHUB_WORKFLOWS_PERMISSION_MISSING: z.number().int().optional(), GITHUB_REBASE_MERGE_REFUSED: z.number().int().optional()}); export const checksOutcomeGroupResponse = z.object({base_ref: z.string(), queue_name: z.string(), priority_rule_name: z.string().nullable(), stats: queueChecksOutcome}); export const checksOutcomeResponse = z.object({groups: z.array(checksOutcomeGroupResponse)}); 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 queue checks outcome for the repository * * GET /repos/{owner}/{repository}/stats/merge_queue_checks_outcome * * Also accepts auth: MergifyTokenBearerAuth, GitHubTokenBearerAuth */ export const getApiReposOwnerRepositoryStatsMergeQueueChecksOutcome = async (args: GetApiReposOwnerRepositoryStatsMergeQueueChecksOutcomeArgs, options: GetApiReposOwnerRepositoryStatsMergeQueueChecksOutcomeOptions) => { const {baseUrl, fetch: fetchFn = fetch, AdminApplicationKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.base_ref ?? []) query.append("base_ref", String(item)) for (const item of args.queue_name ?? []) query.append("queue_name", String(item)) for (const item of args.priority_rule_name ?? []) query.append("priority_rule_name", String(item)) if (args.start_at != null) query.append("start_at", String(args.start_at)) if (args.end_at != null) query.append("end_at", String(args.end_at)) if (AdminApplicationKey !== undefined) headers.set('authorization', `Bearer ${AdminApplicationKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/repos/${encodeURIComponent(String(args.owner))}/${encodeURIComponent(String(args.repository))}/stats/merge_queue_checks_outcome${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(checksOutcomeResponse, await res.json()) };