Class: RosettAi::GitHooks::Installer
- Inherits:
-
Object
- Object
- RosettAi::GitHooks::Installer
- Defined in:
- lib/rosett_ai/git_hooks/installer.rb
Overview
Installs and uninstalls rosett-ai-managed git hooks in .git/hooks/.
Reads hook definitions from .rosett-ai/config.yml and generates POSIX sh scripts that invoke rai commands. Chains to pre-existing hooks (overcommit, husky, lefthook) without overwriting them.
Constant Summary collapse
- RAI_MARKER =
Returns Marker identifying rai-managed hook scripts.
'# rosett-ai-managed hook'- BACKUP_SUFFIX =
Returns File extension appended to backup copies.
'.rosett-ai-backup'- SUPPORTED_HOOKS =
Returns Git hook types supported for installation.
[ 'pre-commit', 'post-commit', 'post-checkout', 'post-merge', 'pre-push' ].freeze
Instance Method Summary collapse
-
#initialize(project_root:, hooks_config:) ⇒ Installer
constructor
A new instance of Installer.
-
#install ⇒ Hash
Installs all configured hooks.
-
#list ⇒ Array<Hash>
Lists currently installed rai hooks.
-
#status ⇒ Hash
Reports drift between config and installed hooks.
-
#uninstall ⇒ Hash
Uninstalls all rosett-ai-managed hooks, restoring backups.
Constructor Details
#initialize(project_root:, hooks_config:) ⇒ Installer
Returns a new instance of Installer.
30 31 32 33 34 |
# File 'lib/rosett_ai/git_hooks/installer.rb', line 30 def initialize(project_root:, hooks_config:) @project_root = Pathname.new(project_root) @hooks_config = hooks_config @hooks_dir = @project_root.join('.git', 'hooks') end |
Instance Method Details
#install ⇒ Hash
Installs all configured hooks.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rosett_ai/git_hooks/installer.rb', line 39 def install results = { installed: [], skipped: [], errors: [] } unless @hooks_dir.directory? results[:errors] << 'Not a git repository (missing .git/hooks/)' return results end @hooks_config.each do |hook_name, commands| normalized = normalize_hook_name(hook_name) install_hook(normalized, Array(commands), results) end results end |
#list ⇒ Array<Hash>
Lists currently installed rai hooks.
73 74 75 76 77 78 79 80 |
# File 'lib/rosett_ai/git_hooks/installer.rb', line 73 def list SUPPORTED_HOOKS.filter_map do |hook| path = @hooks_dir.join(hook) next unless path.exist? && rai_managed?(path) { name: hook, commands: extract_commands(path) } end end |
#status ⇒ Hash
Reports drift between config and installed hooks.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rosett_ai/git_hooks/installer.rb', line 85 def status result = { in_sync: [], missing: [], extra: [], drifted: [] } configured = @hooks_config.transform_keys { |key| normalize_hook_name(key) } configured.each do |hook_name, commands| path = @hooks_dir.join(hook_name) classify_hook(path, hook_name, Array(commands), result) end find_extra_hooks(configured, result) result end |
#uninstall ⇒ Hash
Uninstalls all rosett-ai-managed hooks, restoring backups.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rosett_ai/git_hooks/installer.rb', line 58 def uninstall results = { removed: [], restored: [], errors: [] } unless @hooks_dir.directory? results[:errors] << 'Not a git repository (missing .git/hooks/)' return results end SUPPORTED_HOOKS.each { |hook| uninstall_hook(hook, results) } results end |