feat(git-master): validate git_env_prefix values
This commit is contained in:
@@ -10,6 +10,7 @@ export * from "./schema/commands"
|
|||||||
export * from "./schema/dynamic-context-pruning"
|
export * from "./schema/dynamic-context-pruning"
|
||||||
export * from "./schema/experimental"
|
export * from "./schema/experimental"
|
||||||
export * from "./schema/fallback-models"
|
export * from "./schema/fallback-models"
|
||||||
|
export * from "./schema/git-env-prefix"
|
||||||
export * from "./schema/git-master"
|
export * from "./schema/git-master"
|
||||||
export * from "./schema/hooks"
|
export * from "./schema/hooks"
|
||||||
export * from "./schema/notification"
|
export * from "./schema/notification"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
const GIT_ENV_ASSIGNMENT_PATTERN =
|
||||||
|
/^(?:[A-Za-z_][A-Za-z0-9_]*=[A-Za-z0-9_-]*)(?: [A-Za-z_][A-Za-z0-9_]*=[A-Za-z0-9_-]*)*$/
|
||||||
|
|
||||||
|
export const GIT_ENV_PREFIX_VALIDATION_MESSAGE =
|
||||||
|
'git_env_prefix must be empty or use shell-safe env assignments like "GIT_MASTER=1"'
|
||||||
|
|
||||||
|
export function isValidGitEnvPrefix(value: string): boolean {
|
||||||
|
if (value === "") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return GIT_ENV_ASSIGNMENT_PATTERN.test(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function assertValidGitEnvPrefix(value: string): string {
|
||||||
|
if (!isValidGitEnvPrefix(value)) {
|
||||||
|
throw new Error(GIT_ENV_PREFIX_VALIDATION_MESSAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GitEnvPrefixSchema = z
|
||||||
|
.string()
|
||||||
|
.refine(isValidGitEnvPrefix, { message: GIT_ENV_PREFIX_VALIDATION_MESSAGE })
|
||||||
|
.default("GIT_MASTER=1")
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { GitEnvPrefixSchema } from "./git-env-prefix"
|
||||||
|
|
||||||
export const GitMasterConfigSchema = z.object({
|
export const GitMasterConfigSchema = z.object({
|
||||||
/** Add "Ultraworked with Sisyphus" footer to commit messages (default: true). Can be boolean or custom string. */
|
/** Add "Ultraworked with Sisyphus" footer to commit messages (default: true). Can be boolean or custom string. */
|
||||||
commit_footer: z.union([z.boolean(), z.string()]).default(true),
|
commit_footer: z.union([z.boolean(), z.string()]).default(true),
|
||||||
/** Add "Co-authored-by: Sisyphus" trailer to commit messages (default: true) */
|
/** Add "Co-authored-by: Sisyphus" trailer to commit messages (default: true) */
|
||||||
include_co_authored_by: z.boolean().default(true),
|
include_co_authored_by: z.boolean().default(true),
|
||||||
/** Environment variable prefix for all git commands (default: "GIT_MASTER=1"). Set to "" to disable. Allows custom git hooks to detect git-master skill usage. */
|
/** Environment variable prefix for all git commands (default: "GIT_MASTER=1"). Set to "" to disable. Allows custom git hooks to detect git-master skill usage. */
|
||||||
git_env_prefix: z.string().default("GIT_MASTER=1"),
|
git_env_prefix: GitEnvPrefixSchema,
|
||||||
})
|
})
|
||||||
|
|
||||||
export type GitMasterConfig = z.infer<typeof GitMasterConfigSchema>
|
export type GitMasterConfig = z.infer<typeof GitMasterConfigSchema>
|
||||||
|
|||||||
Reference in New Issue
Block a user