import {z} from 'zod' export type GetApiReposOwnerRepoMilestonesMilestoneNumberLabelsArgs = {owner: string, repo: string, milestone_number: number, per_page?: number | undefined, page?: number | undefined}; export type GetApiReposOwnerRepoMilestonesMilestoneNumberLabelsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; 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 label = z.object({id: z.number().int(), node_id: z.string(), url: z.string(), name: z.string(), description: z.string().nullable(), color: z.string(), default: z.boolean(), archived_at: z.string().nullable(), archived_by: simpleUser.nullable()}); export const getApiReposOwnerRepoMilestonesMilestoneNumberLabelsResponse = z.array(label); 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 labels for issues in a milestone * * GET /repos/{owner}/{repo}/milestones/{milestone_number}/labels */ export const getApiReposOwnerRepoMilestonesMilestoneNumberLabels = async (args: GetApiReposOwnerRepoMilestonesMilestoneNumberLabelsArgs, options?: GetApiReposOwnerRepoMilestonesMilestoneNumberLabelsOptions) => { const {baseUrl = "https://api.github.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) const url = `${baseUrl.replace(/\/+$/, '')}/repos/${encodeURIComponent(String(args.owner))}/${encodeURIComponent(String(args.repo))}/milestones/${encodeURIComponent(String(args.milestone_number))}/labels${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(getApiReposOwnerRepoMilestonesMilestoneNumberLabelsResponse, await res.json()) };