Class: Overcommit::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/overcommit/printer.rb

Overview

Provide a set of callbacks which can be executed as events occur during the course of HookRunner#run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger, context) ⇒ Printer

Returns a new instance of Printer.



11
12
13
14
15
16
17
# File 'lib/overcommit/printer.rb', line 11

def initialize(config, logger, context)
  @config = config
  @log = logger
  @context = context
  @lock = Monitor.new # Need to use monitor so we can have re-entrant locks
  synchronize_all_methods
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



9
10
11
# File 'lib/overcommit/printer.rb', line 9

def log
  @log
end

Instance Method Details

#end_hook(hook, status, output) ⇒ Object

Executed at the end of an individual hook run.



37
38
39
40
41
42
43
# File 'lib/overcommit/printer.rb', line 37

def end_hook(hook, status, output)
  # Want to print the header for quiet hooks only if the result wasn't good
  # so that the user knows what failed
  print_header(hook) if (!hook.quiet? && !@config['quiet']) || status != :pass

  print_result(hook, status, output)
end

#hook_run_failed(message) ⇒ Object



81
82
83
84
85
# File 'lib/overcommit/printer.rb', line 81

def hook_run_failed(message)
  log.newline
  log.log message
  log.newline
end

#hook_skipped(hook) ⇒ Object



28
29
30
# File 'lib/overcommit/printer.rb', line 28

def hook_skipped(hook)
  log.warning "Skipping #{hook.name}"
end

#interrupt_triggeredObject



45
46
47
48
# File 'lib/overcommit/printer.rb', line 45

def interrupt_triggered
  log.newline
  log.error 'Interrupt signal received. Stopping hooks...'
end

#nothing_to_runObject



24
25
26
# File 'lib/overcommit/printer.rb', line 24

def nothing_to_run
  log.debug "✓ No applicable #{hook_script_name} hooks to run"
end

#required_hook_not_skipped(hook) ⇒ Object



32
33
34
# File 'lib/overcommit/printer.rb', line 32

def required_hook_not_skipped(hook)
  log.warning "Cannot skip #{hook.name} since it is required"
end

#run_failedObject

Executed when one or more hooks by the end of the run.



59
60
61
62
63
# File 'lib/overcommit/printer.rb', line 59

def run_failed
  log.newline
  log.error "✗ One or more #{hook_script_name} hooks failed"
  log.newline
end

#run_interruptedObject

Executed when a hook run was interrupted/cancelled by user.



51
52
53
54
55
56
# File 'lib/overcommit/printer.rb', line 51

def run_interrupted
  log.newline
  log.warning '⚠  Hook run interrupted by user'
  log.warning '⚠  If files appear modified/missing, check your stash to recover them'
  log.newline
end

#run_succeededObject

Executed when no hooks failed by the end of the run.



73
74
75
76
77
78
79
# File 'lib/overcommit/printer.rb', line 73

def run_succeeded
  unless @config['quiet']
    log.newline
    log.success "✓ All #{hook_script_name} hooks passed"
    log.newline
  end
end

#run_warnedObject

Executed when no hooks failed by the end of the run, but some warned.



66
67
68
69
70
# File 'lib/overcommit/printer.rb', line 66

def run_warned
  log.newline
  log.warning "⚠ All #{hook_script_name} hooks passed, but with warnings"
  log.newline
end

#start_runObject

Executed at the very beginning of running the collection of hooks.



20
21
22
# File 'lib/overcommit/printer.rb', line 20

def start_run
  log.bold "Running #{hook_script_name} hooks" unless @config['quiet']
end