/** * @fileoverview Git Hooks Integration for Security Scanning * @module @nahisaho/musubix-security/integrations/git-hooks * * Provides pre-commit and pre-push hooks for automated security checks. */ import type { ScanResult, Severity } from '../types/index.js'; /** * Hook type */ export type HookType = 'pre-commit' | 'pre-push' | 'commit-msg' | 'post-commit'; /** * Git hooks configuration */ export interface GitHooksConfig { /** Hooks to install */ hooks: HookType[]; /** Fail on specific severities */ failOn?: Severity[]; /** Scan staged files only (for pre-commit) */ stagedOnly?: boolean; /** File patterns to include */ includePatterns?: string[]; /** File patterns to exclude */ excludePatterns?: string[]; /** Enable secret detection */ detectSecrets?: boolean; /** Enable vulnerability scanning */ detectVulnerabilities?: boolean; /** Skip hooks in CI environment */ skipInCI?: boolean; /** Timeout in seconds */ timeout?: number; /** Custom hook scripts */ customScripts?: Partial>; } /** * Hook execution result */ export interface HookResult { /** Hook type */ hook: HookType; /** Whether hook passed */ passed: boolean; /** Execution time in ms */ executionTime: number; /** Files scanned */ filesScanned: string[]; /** Scan result (if performed) */ scanResult?: ScanResult; /** Error message (if failed) */ error?: string; /** Skipped reason */ skippedReason?: string; } /** * Hook installation result */ export interface InstallResult { /** Hooks installed */ installed: HookType[]; /** Hooks that failed to install */ failed: { hook: HookType; error: string; }[]; /** Git directory path */ gitDir: string; /** Whether backup was created */ backupCreated: boolean; } /** * Staged file info */ export interface StagedFile { /** File path */ path: string; /** Git status */ status: 'A' | 'M' | 'D' | 'R' | 'C'; /** Old path (for renames) */ oldPath?: string; } /** * Manages Git hooks for security scanning * * @example * ```typescript * const hooks = createGitHooks({ * hooks: ['pre-commit', 'pre-push'], * failOn: ['critical', 'high'], * detectSecrets: true, * }); * * // Install hooks * const result = await hooks.install(); * * // Run pre-commit manually * const hookResult = await hooks.runHook('pre-commit'); * ``` */ export declare class GitHooksManager { private config; constructor(config: GitHooksConfig); /** * Install git hooks */ install(workDir?: string): Promise; /** * Uninstall git hooks */ uninstall(workDir?: string): Promise<{ removed: HookType[]; restored: HookType[]; }>; /** * Run a specific hook */ runHook(hook: HookType, workDir?: string): Promise; /** * Get staged files */ getStagedFiles(workDir?: string): Promise; /** * Generate hook script content */ generateHookScript(hook: HookType): string; /** * Check if hooks should be skipped */ shouldSkip(): boolean; /** * Get hook status */ getStatus(workDir?: string): Promise>; private findGitDir; private getAllFiles; private shouldIncludeFile; private matchPattern; private runSecurityScan; private checkResult; private formatError; } /** * Create a git hooks manager */ export declare function createGitHooks(config: GitHooksConfig): GitHooksManager; /** * Quick install pre-commit hook */ export declare function installPreCommitHook(workDir?: string): Promise; /** * Quick install all recommended hooks */ export declare function installRecommendedHooks(workDir?: string): Promise; //# sourceMappingURL=git-hooks.d.ts.map