Module: DocOpsLab::Dev::GitHooks
- Defined in:
- lib/docopslab/dev/git_hooks.rb
Class Method Summary collapse
- .check_hook_updates ⇒ Object
- .install_missing_hooks ⇒ Object
- .list_hook_templates ⇒ Object
- .update_hooks_interactive ⇒ Object
Class Method Details
.check_hook_updates ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/docopslab/dev/git_hooks.rb', line 25 def check_hook_updates return puts 'ℹ️ No .git directory found' unless Dir.exist?(hooks_dir) updates_available = false Dir.glob("#{hooks_template_dir}/*.sh").each do |template_path| hook_name = File.basename(template_path, '.sh') hook_path = File.join(hooks_dir, hook_name) if File.exist?(hook_path) template_content = File.read(template_path) current_content = File.read(hook_path) if template_content != current_content puts "🔄 Update available for #{hook_name} hook" updates_available = true end else puts "➕ New hook template available: #{hook_name}" updates_available = true end end if updates_available puts "Run 'rake labdev:sync:hooks' to update hooks interactively" else puts '✅ All hooks are up to date' end end |
.install_missing_hooks ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/docopslab/dev/git_hooks.rb', line 9 def install_missing_hooks return unless Dir.exist?(hooks_dir) Dir.glob("#{hooks_template_dir}/*.sh").each do |template_path| hook_name = File.basename(template_path, '.sh') hook_path = File.join(hooks_dir, hook_name) next if File.exist?(hook_path) puts "🪝 Installing #{hook_name} hook..." FileUtils.cp(template_path, hook_path) File.chmod(0o755, hook_path) puts "✅ #{hook_name} hook installed" end end |
.list_hook_templates ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/docopslab/dev/git_hooks.rb', line 97 def list_hook_templates puts '📋 Available git hook templates:' puts '' Dir.glob("#{hooks_template_dir}/*.sh").each do |template_path| hook_name = File.basename(template_path, '.sh') hook_path = File.join(hooks_dir, hook_name) status = nil if File.exist?(hook_path) template_content = File.read(template_path) current_content = File.read(hook_path) status = template_content == current_content ? '✅ installed' : '🔄 update available' else status = '➕ not installed' end description = case hook_name when 'pre-commit' 'Advisory checks & syntax validation (non-blocking)' when 'pre-push' 'Comprehensive linting & quality gate (blocking)' else '' end puts " #{hook_name}: #{status}" puts " #{description}" unless description.empty? end end |
.update_hooks_interactive ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/docopslab/dev/git_hooks.rb', line 55 def update_hooks_interactive return puts 'ℹ️ No .git directory found' unless Dir.exist?(hooks_dir) Dir.glob("#{hooks_template_dir}/*.sh").each do |template_path| hook_name = File.basename(template_path, '.sh') hook_path = File.join(hooks_dir, hook_name) if File.exist?(hook_path) template_content = File.read(template_path) current_content = File.read(hook_path) next if template_content == current_content puts "🔄 #{hook_name} hook has updates available" puts "Current file exists at: #{hook_path}" print "Update #{hook_name} hook? [y/N]: " response = $stdin.gets.chomp.downcase if %w[y yes].include?(response) File.write(hook_path, template_content) File.chmod(0o755, hook_path) puts "✅ #{hook_name} hook updated" else puts "⏭️ Skipped #{hook_name} hook" end else puts "➕ New hook template: #{hook_name}" print "Install #{hook_name} hook? [Y/n]: " response = $stdin.gets.chomp.downcase if response != 'n' && response != 'no' FileUtils.cp(template_path, hook_path) File.chmod(0o755, hook_path) puts "✅ #{hook_name} hook installed" else puts "⏭️ Skipped #{hook_name} hook" end end end end |