forked from
tangled.org/core
Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
1import { z } from "zod";
2
3const hexColor = /^#[0-9A-Fa-f]{6}$/;
4
5const languageSchema = z.object({
6 color: z.string().regex(hexColor),
7 percentage: z.number().min(0).max(100),
8});
9
10export const repositoryCardSchema = z.object({
11 type: z.literal("repository"),
12 repoName: z.string().min(1).max(100),
13 ownerHandle: z.string().min(1).max(100),
14 stars: z.number().int().min(0).max(1000000),
15 pulls: z.number().int().min(0).max(100000),
16 issues: z.number().int().min(0).max(100000),
17 createdAt: z.string().max(100),
18 avatarUrl: z.string().url(),
19 languages: z.array(languageSchema).max(5),
20});
21
22export const issueCardSchema = z.object({
23 type: z.literal("issue"),
24 repoName: z.string().min(1).max(100),
25 ownerHandle: z.string().min(1).max(100),
26 avatarUrl: z.string().url(),
27 title: z.string().min(1).max(500),
28 issueNumber: z.number().int().positive(),
29 status: z.enum(["open", "closed"]),
30 labels: z
31 .array(
32 z.object({
33 name: z.string().max(50),
34 color: z.string().regex(hexColor),
35 }),
36 )
37 .max(10),
38 commentCount: z.number().int().min(0),
39 reactionCount: z.number().int().min(0),
40 createdAt: z.string(),
41});
42
43export const pullRequestCardSchema = z.object({
44 type: z.literal("pullRequest"),
45 repoName: z.string().min(1).max(100),
46 ownerHandle: z.string().min(1).max(100),
47 avatarUrl: z.string().url(),
48 title: z.string().min(1).max(500),
49 pullRequestNumber: z.number().int().positive(),
50 status: z.enum(["open", "closed", "merged"]),
51 filesChanged: z.number().int().min(0),
52 additions: z.number().int().min(0),
53 deletions: z.number().int().min(0),
54 rounds: z.number().int().min(1),
55 // reviews: z.number().int().min(0), // TODO: implement review tracking
56 commentCount: z.number().int().min(0),
57 reactionCount: z.number().int().min(0),
58 createdAt: z.string(),
59});
60
61export const cardPayloadSchema = z.discriminatedUnion("type", [
62 repositoryCardSchema,
63 issueCardSchema,
64 pullRequestCardSchema,
65]);
66
67export type Language = z.infer<typeof languageSchema>;
68export type RepositoryCardData = z.infer<typeof repositoryCardSchema>;
69export type IssueCardData = z.infer<typeof issueCardSchema>;
70export type PullRequestCardData = z.infer<typeof pullRequestCardSchema>;