import {z} from 'zod' export type IssueStatus = 'open' | 'in_progress' | 'completed' | 'not_planned'; export type UpdateIssueRequest = {assignees?: (Array | null) | undefined, body?: (string | null) | undefined, confidential?: (boolean | null) | undefined, labelsAdd?: (Array | null) | undefined, labelsRemove?: (Array | null) | undefined, locked?: (boolean | null) | undefined, milestoneId?: (string | null) | undefined, priority?: (string | null) | undefined, status?: (IssueStatus | null) | undefined, title?: (string | null) | undefined}; export type PatchApiApiReposNamespaceRepositoryIssuesIndexArgs = {namespace: string, repository: string, index: number, body: UpdateIssueRequest}; export type PatchApiApiReposNamespaceRepositoryIssuesIndexOptions = {baseUrl: string, cookieAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const milestoneBrief = z.object({closed: z.boolean(), due_date: z.string().nullable().optional(), id: z.string(), title: z.string()}); export const reactionGroup = z.object({count: z.number().int(), emoji: z.string(), reacted: z.boolean()}); export const issueStatus = z.enum(["open", "in_progress", "completed", "not_planned"]); export const issueResponse = z.object({assignee_ids: z.array(z.string()), assignees: z.array(z.string()), author_id: z.string(), author_username: z.string(), body: z.string(), comment_count: z.number().int(), git_bug_id: z.string(), id: z.string(), index: z.number().int(), labels: z.array(z.string()), milestone: milestoneBrief.nullable().optional(), priority: z.string(), reactions: z.array(reactionGroup), status: issueStatus, title: z.string(), updated_at: z.string()}); 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 }; /** * Update Issue * * PATCH /api/repos/{namespace}/{repository}/issues/{index} */ export const patchApiApiReposNamespaceRepositoryIssuesIndex = async (args: PatchApiApiReposNamespaceRepositoryIssuesIndexArgs, options: PatchApiApiReposNamespaceRepositoryIssuesIndexOptions) => { const {baseUrl, fetch: fetchFn = fetch, cookieAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (cookieAuth !== undefined) cookies.push("gitarena-session=" + encodeURIComponent(cookieAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/api/repos/${encodeURIComponent(String(args.namespace))}/${encodeURIComponent(String(args.repository))}/issues/${encodeURIComponent(String(args.index))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(issueResponse, await res.json()) };