kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
at main 73 lines 1.8 kB view raw
1import * as v from "valibot"; 2 3export const branchPatterns = [ 4 "{slug}-{number}", 5 "{slug}-{number}-{title}", 6 "{number}", 7 "{number}-{title}", 8 "feature/{slug}-{number}", 9 "feature/{number}-{title}", 10 "fix/{slug}-{number}", 11 "fix/{number}-{title}", 12] as const; 13 14export type BranchPattern = (typeof branchPatterns)[number] | "custom"; 15 16export const githubConfigSchema = v.object({ 17 repositoryOwner: v.string(), 18 repositoryName: v.string(), 19 installationId: v.nullable(v.number()), 20 branchPattern: v.optional(v.string()), 21 customBranchRegex: v.optional(v.string()), 22 statusTransitions: v.optional( 23 v.object({ 24 onBranchPush: v.optional(v.string()), 25 onPROpen: v.optional(v.string()), 26 onPRMerge: v.optional(v.string()), 27 }), 28 ), 29}); 30 31export type GitHubConfig = v.InferOutput<typeof githubConfigSchema>; 32 33export async function validateGitHubConfig( 34 config: unknown, 35): Promise<{ valid: boolean; errors?: string[] }> { 36 try { 37 v.parse(githubConfigSchema, config); 38 return { valid: true }; 39 } catch (error) { 40 if (error instanceof v.ValiError) { 41 return { 42 valid: false, 43 errors: error.issues.map((issue) => issue.message), 44 }; 45 } 46 return { 47 valid: false, 48 errors: [error instanceof Error ? error.message : "Invalid config"], 49 }; 50 } 51} 52 53export const defaultGitHubConfig: Partial<GitHubConfig> = { 54 branchPattern: "{slug}-{number}", 55 statusTransitions: { 56 onBranchPush: "in-progress", 57 onPROpen: "in-review", 58 onPRMerge: "done", 59 }, 60}; 61 62export function getDefaultConfig( 63 repositoryOwner: string, 64 repositoryName: string, 65 installationId: number | null = null, 66): GitHubConfig { 67 return { 68 repositoryOwner, 69 repositoryName, 70 installationId, 71 ...defaultGitHubConfig, 72 }; 73}