import {z} from 'zod' export type CreateApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsArgs = {owner: string, repo: string, run_id: number, body: {environment_ids: Array, state: 'approved' | 'rejected', comment: string}}; export type CreateApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const nullableSimpleUser = z.object({name: z.string().nullable().optional(), email: z.string().nullable().optional(), login: z.string(), id: z.number().int(), node_id: z.string(), avatar_url: z.string(), gravatar_id: z.string().nullable(), url: z.string(), html_url: z.string(), followers_url: z.string(), following_url: z.string(), gists_url: z.string(), starred_url: z.string(), subscriptions_url: z.string(), organizations_url: z.string(), repos_url: z.string(), events_url: z.string(), received_events_url: z.string(), type: z.string(), site_admin: z.boolean(), starred_at: z.string().optional(), user_view_type: z.string().optional()}).nullable(); export const simpleUser = z.object({name: z.string().nullable().optional(), email: z.string().nullable().optional(), login: z.string(), id: z.number().int(), node_id: z.string(), avatar_url: z.string(), gravatar_id: z.string().nullable(), url: z.string(), html_url: z.string(), followers_url: z.string(), following_url: z.string(), gists_url: z.string(), starred_url: z.string(), subscriptions_url: z.string(), organizations_url: z.string(), repos_url: z.string(), events_url: z.string(), received_events_url: z.string(), type: z.string(), site_admin: z.boolean(), starred_at: z.string().optional(), user_view_type: z.string().optional()}); export const enterprise = z.object({description: z.string().nullable().optional(), html_url: z.string(), website_url: z.string().nullable().optional(), id: z.number().int(), node_id: z.string(), name: z.string(), slug: z.string(), created_at: z.string().nullable(), updated_at: z.string().nullable(), avatar_url: z.string()}); export const nullableIntegration = z.object({id: z.number().int(), slug: z.string().optional(), node_id: z.string(), client_id: z.string().optional(), owner: z.union([simpleUser, enterprise]), name: z.string(), description: z.string().nullable(), external_url: z.string(), html_url: z.string(), created_at: z.string(), updated_at: z.string(), permissions: z.object({issues: z.string().optional(), checks: z.string().optional(), metadata: z.string().optional(), contents: z.string().optional(), deployments: z.string().optional()}).and(z.record(z.string(), z.string())), events: z.array(z.string()), installations_count: z.number().int().optional()}).nullable(); export const deployment = z.object({url: z.string(), id: z.number().int(), node_id: z.string(), sha: z.string(), ref: z.string(), task: z.string(), payload: z.union([z.record(z.string(), z.unknown()), z.string()]), original_environment: z.string().optional(), environment: z.string(), description: z.string().nullable(), creator: nullableSimpleUser, created_at: z.string(), updated_at: z.string(), statuses_url: z.string(), repository_url: z.string(), transient_environment: z.boolean().optional(), production_environment: z.boolean().optional(), performed_via_github_app: nullableIntegration.optional()}); export const createApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsResponse = z.array(deployment); 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 }; /** * Review pending deployments for a workflow run * * POST /repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments */ export const createApiReposOwnerRepoActionsRunsRunIdPendingDeployments = async (args: CreateApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsArgs, options?: CreateApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsOptions) => { const {baseUrl = "https://api.github.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/repos/${encodeURIComponent(String(args.owner))}/${encodeURIComponent(String(args.repo))}/actions/runs/${encodeURIComponent(String(args.run_id))}/pending_deployments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiReposOwnerRepoActionsRunsRunIdPendingDeploymentsResponse, await res.json()) };