| 1 | import { z } from "zod"; |
| 2 | |
| 3 | import type { IssueTimelineItem |
| 4 | |
| 5 | export const issueStates = |
| 6 | export const issueFilters = |
| 7 | |
| 8 | export type IssueState |
| 9 | export type IssueFilter |
| 10 | |
| 11 | export const issueSorts = |
| 12 | export type IssueSort |
| 13 | |
| 14 | export const createIssueSchema = |
| 15 | title: z |
| 16 | .string() |
| 17 | .min(1, " |
| 18 | .max(200, " |
| 19 | body: z |
| 20 | .string() |
| 21 | .max(20000, " |
| 22 | .optional(), |
| 23 | labels: z.array |
| 24 | assignees: z.array |
| 25 | }); |
| 26 | |
| 27 | export type CreateIssueInput |
| 28 | |
| 29 | export const createLabelSchema = |
| 30 | name: z |
| 31 | .string() |
| 32 | .trim() |
| 33 | .min(1, " |
| 34 | .max(50, " |
| 35 | description: z |
| 36 | .string() |
| 37 | .max(100, " |
| 38 | .optional(), |
| 39 | color: z |
| 40 | .string() |
| 41 | .regex(/^[0-9a-fA-F |
| 42 | }); |
| 43 | |
| 44 | export type CreateLabelInput |
| 45 | |
| 46 | // `null` clears the description, which is why it is not just `.optional()`. |
| 47 | export const updateLabelSchema = |
| 48 | description: createLabelSchema.shape |
| 49 | }); |
| 50 | |
| 51 | /** What happened, without who did it: the timeline links the actor in front of it. */ |
| 52 | export function eventDescription( |
| 53 | event: { |
| 54 | type: string |
| 55 | labelName: string |
| 56 | assigneeUsername: string |
| 57 | oldTitle: string |
| 58 | newTitle: string |
| 59 | }, |
| 60 | noun: "issue |
| 61 | ): string { |
| 62 | switch (event.type |
| 63 | case "opened": |
| 64 | return `opened this ${noun |
| 65 | case "closed": |
| 66 | return `closed this ${noun |
| 67 | case "reopened": |
| 68 | return `reopened this ${noun |
| 69 | case "merged": |
| 70 | return `merged this ${noun |
| 71 | case "ready_for_review": |
| 72 | return `marked this ${noun |
| 73 | case "converted_to_draft": |
| 74 | return `marked this ${noun |
| 75 | case "renamed": |
| 76 | return `renamed this ${noun |
| 77 | case "edited": |
| 78 | return `edited the description`; |
| 79 | case "labeled": |
| 80 | return `added the “${event |
| 81 | case "unlabeled": |
| 82 | return `removed the “${event |
| 83 | case "assigned": |
| 84 | return `assigned ${event |
| 85 | case "unassigned": |
| 86 | return `unassigned ${event |
| 87 | default: |
| 88 | return `updated this ${noun |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | type TimelineEvent |
| 93 | |
| 94 | const isCommitBy = ( |
| 95 | item?.kind === |
| 96 | item.event.type |
| 97 | item.event.actorUsername |
| 98 | |
| 99 | /** The commits one person added in a row, starting at `index`, which read as one block; null for a commit that continues the block before it. */ |
| 100 | export function commitRunAt( |
| 101 | items: IssueTimelineItem |
| 102 | index: number, |
| 103 | ): TimelineEvent[] |
| 104 | const item = |
| 105 | if (item?.kind |
| 106 | const actor = |
| 107 | if (isCommitBy(items |
| 108 | |
| 109 | const run: |
| 110 | for (let at |
| 111 | const next = |
| 112 | if (next.kind |
| 113 | } |
| 114 | return run; |
| 115 | } |