| 1 | import { z } from "zod"; |
| 2 | |
| 3 | export const issueStates = |
| 4 | export const issueFilters = |
| 5 | |
| 6 | export type IssueState |
| 7 | export type IssueFilter |
| 8 | |
| 9 | export const issueSorts = |
| 10 | export type IssueSort |
| 11 | |
| 12 | export const issueDirections = |
| 13 | export type IssueDirection |
| 14 | |
| 15 | export const createIssueSchema = |
| 16 | title: z |
| 17 | .string() |
| 18 | .min(1, " |
| 19 | .max(200, " |
| 20 | body: z |
| 21 | .string() |
| 22 | .max(20000, " |
| 23 | .optional(), |
| 24 | labels: z.array |
| 25 | assignees: z.array |
| 26 | }); |
| 27 | |
| 28 | export type CreateIssueInput |
| 29 | |
| 30 | export const createLabelSchema = |
| 31 | name: z |
| 32 | .string() |
| 33 | .trim() |
| 34 | .min(1, " |
| 35 | .max(50, " |
| 36 | description: z |
| 37 | .string() |
| 38 | .max(100, " |
| 39 | .optional(), |
| 40 | color: z |
| 41 | .string() |
| 42 | .regex(/^[0-9a-fA-F |
| 43 | }); |
| 44 | |
| 45 | export type CreateLabelInput |
| 46 | |
| 47 | // `null` clears the description, which is why it is not just `.optional()`. |
| 48 | export const updateLabelSchema = |
| 49 | description: createLabelSchema.shape |
| 50 | }); |
| 51 | |
| 52 | export type UpdateLabelInput |
| 53 | |
| 54 | /** What happened, without who did it: the timeline links the actor in front of it. */ |
| 55 | export function eventDescription( |
| 56 | event: { |
| 57 | type: string |
| 58 | labelName: string |
| 59 | assigneeUsername: string |
| 60 | oldTitle: string |
| 61 | newTitle: string |
| 62 | }, |
| 63 | noun: "issue |
| 64 | ): string { |
| 65 | switch (event.type |
| 66 | case "opened": |
| 67 | return `opened this ${noun |
| 68 | case "closed": |
| 69 | return `closed this ${noun |
| 70 | case "reopened": |
| 71 | return `reopened this ${noun |
| 72 | case "merged": |
| 73 | return `merged this ${noun |
| 74 | case "ready_for_review": |
| 75 | return `marked this ${noun |
| 76 | case "converted_to_draft": |
| 77 | return `marked this ${noun |
| 78 | case "renamed": |
| 79 | return `renamed this ${noun |
| 80 | case "edited": |
| 81 | return `edited the description`; |
| 82 | case "labeled": |
| 83 | return `added the “${event |
| 84 | case "unlabeled": |
| 85 | return `removed the “${event |
| 86 | case "assigned": |
| 87 | return `assigned ${event |
| 88 | case "unassigned": |
| 89 | return `unassigned ${event |
| 90 | default: |
| 91 | return `updated this ${noun |
| 92 | } |
| 93 | } |