1
1
module Overcommit
2
2
class Reporter
3
- include ConsoleMethods
4
-
5
3
def initialize ( name , checks )
6
4
@name = name
7
5
@checks = checks
@@ -11,7 +9,7 @@ def initialize(name, checks)
11
9
12
10
def with_status ( check , &block )
13
11
title = " Checking #{ check . name } ..."
14
- print title unless check . stealth?
12
+ log . partial title unless check . stealth?
15
13
16
14
status , output = yield
17
15
@@ -20,48 +18,53 @@ def with_status(check, &block)
20
18
end
21
19
22
20
def print_header
23
- puts "Running #{ @name } checks"
21
+ log . log "Running #{ @name } checks"
24
22
end
25
23
26
24
def print_result
27
- puts
25
+ log . log # Newline
26
+
28
27
case final_result
29
28
when :good
30
- success "+++ All #{ @name } checks passed"
29
+ log . success "+++ All #{ @name } checks passed"
31
30
exit 0
32
31
when :bad
33
- error "!!! One or more #{ @name } checks failed"
32
+ log . error "!!! One or more #{ @name } checks failed"
34
33
exit 1
35
34
when :stop
36
- warning "*** One or more #{ @name } checks needs attention"
37
- warning "*** If you really want to commit, use SKIP_CHECKS"
38
- warning "*** (takes a space-separated list of checks to skip, or 'all')"
35
+ log . warning "*** One or more #{ @name } checks needs attention"
36
+ log . warning "*** If you really want to commit, use SKIP_CHECKS"
37
+ log . warning "*** (takes a space-separated list of checks to skip, or 'all')"
39
38
exit 1
40
39
end
41
40
end
42
41
43
42
private
44
43
44
+ def log
45
+ Overcommit ::Logger . instance
46
+ end
47
+
45
48
def print_incremental_result ( title , status , output , stealth = false )
46
49
if stealth
47
50
return if status == :good
48
- print title
51
+ log . partial title
49
52
end
50
53
51
54
print '.' * ( @width - title . length )
52
55
case status
53
56
when :good
54
- success 'OK'
57
+ log . success 'OK'
55
58
when :bad
56
- error 'FAILED'
59
+ log . error 'FAILED'
57
60
print_report output
58
61
when :warn
59
- warning output
62
+ log . warning output
60
63
when :stop
61
- warning 'UH OH'
64
+ log . warning 'UH OH'
62
65
print_report output
63
66
else
64
- error '???'
67
+ log . error '???'
65
68
print_report "Check didn't return a status"
66
69
exit 1
67
70
end
@@ -74,7 +77,7 @@ def final_result
74
77
end
75
78
76
79
def print_report ( *report )
77
- puts report . flatten . map { |line | " #{ line } " } . join ( "\n " )
80
+ log . log report . flatten . map { |line | " #{ line } " } . join ( "\n " )
78
81
end
79
82
end
80
83
end
0 commit comments