| 1 | import { z } from "zod"; |
| 2 | |
| 3 | export const repositoryVisibilities = |
| 4 | |
| 5 | export const createRepositorySchema = |
| 6 | owner: z.string |
| 7 | name: z |
| 8 | .string() |
| 9 | .min(1, " |
| 10 | .max(100, " |
| 11 | .regex( |
| 12 | /^[a-zA-Z0-9._-]+$ |
| 13 | "Use letters, numbers, hyphens, underscores or periods.", |
| 14 | ), |
| 15 | description: z |
| 16 | .string() |
| 17 | .max(350, " |
| 18 | .optional(), |
| 19 | visibility: z.enum |
| 20 | }); |
| 21 | |
| 22 | export type CreateRepositoryInput |
| 23 | |
| 24 | const githubSource = z |
| 25 | .string() |
| 26 | .regex( |
| 27 | /^[A-Za-z0-9-]+\/ |
| 28 | "Write the GitHub repository as owner/name.", |
| 29 | ); |
| 30 | |
| 31 | export const importRepositorySchema = |
| 32 | source: githubSource, |
| 33 | }); |
| 34 | |
| 35 | // The new repository form imports when a source is given and creates an empty repository when it is left blank. |
| 36 | export const newRepositorySchema = |
| 37 | source: githubSource.or |
| 38 | }); |
| 39 | |
| 40 | export type NewRepositoryInput |
| 41 | |
| 42 | export const forkRepositorySchema = |
| 43 | |
| 44 | export type ForkRepositoryInput |
| 45 | |
| 46 | // Each settings card saves its own field, so every field is optional. |
| 47 | export const updateRepositorySchema = |
| 48 | .omit({ owner: |
| 49 | .extend({ defaultBranch: |
| 50 | .partial(); |
| 51 | |
| 52 | export type UpdateRepositoryInput |
| 53 | |
| 54 | export const createBranchSchema = |
| 55 | name: z.string |
| 56 | from: z.string |
| 57 | }); |
| 58 | |
| 59 | export type CreateBranchInput |