Submatter/packages/shared/src/connected-repos/schemas.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import { z } from "zod";
export const forgeTypeSchema = z.enum([
"github",
"forgejo",
"gitlab",
"bitbucket",
]);
export type ForgeType = z.infer<typeof forgeTypeSchema>;
export const parsedGitRemoteSchema = z.object({
forgeType: forgeTypeSchema,
gitRemoteUrl: z.string().url(),
webUrl: z.string().url(),
apiBaseUrl: z.string().url(),
owner: z.string().min(1).max(200),
repoName: z.string().min(1).max(200),
});
export type ParsedGitRemote = z.infer<typeof parsedGitRemoteSchema>;
export const connectedRepoSchema = z.object({
id: z.string().uuid(),
workspaceId: z.string().uuid(),
displayName: z.string().min(1).max(200),
gitRemoteUrl: z.string().url(),
forgeType: forgeTypeSchema,
apiBaseUrl: z.string().url(),
owner: z.string().min(1).max(200),
repoName: z.string().min(1).max(200),
defaultBranch: z.string().min(1).max(200).nullable(),
tokenEnvVar: z.string().min(1).max(120).nullable(),
metadata: z.record(z.unknown()).nullable(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
});
export type ConnectedRepo = z.infer<typeof connectedRepoSchema>;
export const repoMetadataSchema = z.object({
defaultBranch: z.string().min(1),
cloneUrl: z.string().url(),
description: z.string().optional(),
});
export type RepoMetadata = z.infer<typeof repoMetadataSchema>;