@@ -33,7 +33,7 @@ def initialize
33
33
plugin_dirs << REPO_SPECIFIC_DIR if File . directory? ( REPO_SPECIFIC_DIR )
34
34
35
35
plugin_dirs . each do |dir |
36
- Dir [ File . join ( dir , hook_name , '*.rb' ) ] . each do |plugin |
36
+ Dir [ File . join ( dir , Overcommit :: Utils . hook_name , '*.rb' ) ] . each do |plugin |
37
37
unless skip_checks . include? File . basename ( plugin , '.rb' )
38
38
begin
39
39
require plugin
@@ -44,14 +44,15 @@ def initialize
44
44
end
45
45
end
46
46
end
47
-
48
- @width = 70 - ( HookRegistry . checks . map { |s | s . name . length } . max || 0 )
49
47
end
50
48
51
49
def run ( *args )
52
50
exit if requires_modified_files? && modified_files . empty?
53
51
54
- puts "Running #{ hook_name } checks"
52
+ reporter = Reporter . new ( Overcommit ::Utils . hook_name , HookRegistry . checks )
53
+
54
+ reporter . print_header
55
+
55
56
results = HookRegistry . checks . map do |check_class |
56
57
check = check_class . new ( *args )
57
58
next if check . skip?
@@ -65,76 +66,19 @@ def run(*args)
65
66
66
67
status , output = check . run_check
67
68
68
- print_incremental_result ( title , status , output , check . stealth? )
69
+ reporter . print_incremental_result ( title , status , output , check . stealth? )
69
70
[ status , output ]
70
71
end . compact
71
72
72
- print_result results
73
- end
74
-
75
- def hook_name
76
- Overcommit ::Utils . hook_name
73
+ reporter . print_result results
77
74
end
78
75
79
- protected
76
+ private
80
77
81
78
# If true, only run this check when there are modified files.
82
79
def requires_modified_files?
83
80
false
84
81
end
85
-
86
- def print_incremental_result ( title , status , output , stealth = false )
87
- if stealth
88
- return if status == :good
89
- print title
90
- end
91
-
92
- print '.' * ( @width - title . length )
93
- case status
94
- when :good
95
- success ( 'OK' )
96
- when :bad
97
- error ( 'FAILED' )
98
- print_report ( output )
99
- when :warn
100
- warning output
101
- when :stop
102
- warning 'UH OH'
103
- print_report ( output )
104
- else
105
- error '???'
106
- print_report ( "Check didn't return a status" )
107
- exit 1
108
- end
109
- end
110
-
111
- def print_result ( results )
112
- puts
113
- case final_result ( results )
114
- when :good
115
- success "+++ All #{ hook_name } checks passed"
116
- exit 0
117
- when :bad
118
- error "!!! One or more #{ hook_name } checks failed"
119
- exit 1
120
- when :stop
121
- warning "*** One or more #{ hook_name } checks needs attention"
122
- warning "*** If you really want to commit, use SKIP_CHECKS"
123
- warning "*** (takes a space-separated list of checks to skip, or 'all')"
124
- exit 1
125
- end
126
- end
127
-
128
- def final_result ( results )
129
- states = ( results . transpose . first || [ ] ) . uniq
130
- return :bad if states . include? ( :bad )
131
- return :stop if states . include? ( :stop )
132
- return :good
133
- end
134
-
135
- def print_report ( *report )
136
- puts report . flatten . map { |line | " #{ line } " } . join ( "\n " )
137
- end
138
82
end
139
83
end
140
84
end
0 commit comments