overcommit 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8d7eb3f46bb777b61a7691c1eef669daf7993b5
4
- data.tar.gz: cf0dc9b2c995254856a82ddf449d271a1d886d8c
3
+ metadata.gz: 1c7ae9be51eb3b0d57670dc28a29c359ec89c040
4
+ data.tar.gz: 6830fbb57c870026962e5ea7b98b74a2ae69ca78
5
5
  SHA512:
6
- metadata.gz: f0fa19bb49c780b3d0a89d3488458339ed81bd20a2d26dc1e9a85f8f26dd3e6c315a75c3e9e1eafd627f09725062450b8a5da0b29ab07e6567b78bd1772a54aa
7
- data.tar.gz: ffbbb87fadc8db06a91fbf052954a13e7d68063935225ff6480b834599ef3a70945f80903dbf6a5d7756170eb559db0c74d296b13c9502380b209dfdaade2add
6
+ metadata.gz: faa4abb76a1d4b681b29bcdf0bfa84d9d55498fd8e472bc654ffd4ce7dd3edbcd49da126f1299ca49efc519f7310b023afb7229c2d03a9ca0b2535eb92ee0f15
7
+ data.tar.gz: 817e12dcedd4b6a624fb9eb5203443fd81279d130f37a65613e30126e71d8337a51f65d6e85a3f930a4d5aa7c13d13c940053851da47793d4bfa536f84021558
data/lib/overcommit.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'overcommit/configuration'
2
- require 'overcommit/console_methods'
3
2
  require 'overcommit/errors'
4
3
  require 'overcommit/git_hook'
5
4
  require 'overcommit/hook_specific_check'
6
5
  require 'overcommit/installer'
6
+ require 'overcommit/logger'
7
7
  require 'overcommit/reporter'
8
8
  require 'overcommit/utils'
9
9
  require 'overcommit/version'
@@ -2,7 +2,6 @@ require 'optparse'
2
2
 
3
3
  module Overcommit
4
4
  class CLI
5
- include ConsoleMethods
6
5
  attr_reader :options
7
6
 
8
7
  def initialize(arguments = [])
@@ -19,14 +18,14 @@ module Overcommit
19
18
  end
20
19
 
21
20
  opts.on_tail('-v', '--version', 'Show version') do
22
- puts VERSION
21
+ log.log VERSION
23
22
  exit 0
24
23
  end
25
24
 
26
25
  opts.on('-l', '--list-templates', 'List built-in templates') do
27
26
  Overcommit.config.templates.each_pair do |name, configuration|
28
27
  bold name
29
- puts YAML.dump(configuration), ''
28
+ log.log YAML.dump(configuration), ''
30
29
  end
31
30
  exit 0
32
31
  end
@@ -80,8 +79,8 @@ module Overcommit
80
79
 
81
80
  def run
82
81
  if @options[:targets].nil? || @options[:targets].empty?
83
- warning 'You must supply at least one directory'
84
- puts @parser.help
82
+ log.warning 'You must supply at least one directory'
83
+ log.log @parser.help
85
84
  exit 2
86
85
  end
87
86
 
@@ -89,11 +88,11 @@ module Overcommit
89
88
  begin
90
89
  Installer.new(@options, target).run
91
90
  rescue NotAGitRepoError => e
92
- warning "Skipping #{target}: #{e}"
91
+ log.warning "Skipping #{target}: #{e}"
93
92
  end
94
93
  end
95
94
 
96
- success "#{@options[:uninstall] ? 'Removal' : 'Installation'} complete"
95
+ log.success "#{@options[:uninstall] ? 'Removal' : 'Installation'} complete"
97
96
 
98
97
  rescue ArgumentError => ex
99
98
  error "Installation failed: #{ex}"
@@ -102,9 +101,13 @@ module Overcommit
102
101
 
103
102
  private
104
103
 
104
+ def log
105
+ Logger.instance
106
+ end
107
+
105
108
  def print_help(message, ex = nil)
106
- error ex.to_s + "\n" if ex
107
- puts message
109
+ log.error ex.to_s + "\n" if ex
110
+ log.log message
108
111
  exit 0
109
112
  end
110
113
  end
@@ -22,7 +22,7 @@ module Overcommit
22
22
  # Given the current configuration, return a set of paths which should be
23
23
  # loaded as plugins (`require`d)
24
24
  def desired_plugins
25
- excludes = repo_settings['excludes']
25
+ excludes = repo_settings['excludes'] || {}
26
26
 
27
27
  plugin_directories.map do |dir|
28
28
  Dir[File.join(dir, Utils.hook_name, '*.rb')].map do |plugin|
@@ -1,14 +1,12 @@
1
1
  module Overcommit
2
2
  module GitHook
3
3
  class BaseHook
4
- include ConsoleMethods
5
-
6
4
  def initialize
7
5
  Overcommit.config.desired_plugins.each do |plugin|
8
6
  require plugin
9
7
  end
10
- rescue NameError => ex
11
- error "Couldn't load plugin: #{ex}"
8
+ rescue LoadError, NameError => ex
9
+ log.error "Couldn't load plugin: #{ex}"
12
10
  exit 0
13
11
  end
14
12
 
@@ -39,8 +37,16 @@ module Overcommit
39
37
  reporter.print_result
40
38
  end
41
39
 
40
+ def skip_checks
41
+ @skip_checks ||= ENV.fetch('SKIP_CHECKS', '').split(/[:, ]/)
42
+ end
43
+
42
44
  private
43
45
 
46
+ def log
47
+ Logger.instance
48
+ end
49
+
44
50
  # Return all loaded plugins, skipping those that are skippable and have
45
51
  # been asked to be skipped by the environment variable SKIP_CHECKS.
46
52
  #
@@ -48,10 +54,9 @@ module Overcommit
48
54
  # `ENV['SKIP_CHECKS'] == 'all'`
49
55
  def registered_checks
50
56
  @registered_checks ||= begin
51
- skip_checks = ENV.fetch('SKIP_CHECKS', '').split(/[:, ]/)
52
- skip_all = skip_checks.include? 'all'
57
+ skip_all = skip_checks.include? 'all'
53
58
  HookRegistry.checks.reject do |check|
54
- hook_name = Utils.underscorize check.name
59
+ hook_name = Utils.underscorize(check.name).split('/').last
55
60
 
56
61
  check.skippable? && (skip_all || skip_checks.include?(hook_name))
57
62
  end
@@ -14,7 +14,7 @@ module Overcommit
14
14
  end
15
15
 
16
16
  def install
17
- puts "Installing hooks into #{@target}"
17
+ log.log "Installing hooks into #{@target}"
18
18
 
19
19
  install_scripts
20
20
  install_hooks
@@ -22,7 +22,7 @@ module Overcommit
22
22
  end
23
23
 
24
24
  def uninstall
25
- puts "Removing hooks from #{@target}"
25
+ log.log "Removing hooks from #{@target}"
26
26
 
27
27
  uninstall_scripts
28
28
  uninstall_hooks
@@ -31,6 +31,10 @@ module Overcommit
31
31
 
32
32
  private
33
33
 
34
+ def log
35
+ Logger.instance
36
+ end
37
+
34
38
  def hook_path
35
39
  absolute_target = File.expand_path @target
36
40
  File.join(absolute_target, '.git/hooks')
@@ -0,0 +1,36 @@
1
+ require 'singleton'
2
+
3
+ # This class centralizes all communication to STDOUT
4
+ module Overcommit
5
+ class Logger
6
+ include Singleton
7
+
8
+ def partial(*args)
9
+ print *args
10
+ end
11
+
12
+ def log(*args)
13
+ puts *args
14
+ end
15
+
16
+ def bold(str)
17
+ log "\033[1;37m#{str}\033[0m"
18
+ end
19
+
20
+ def error(str)
21
+ log "\033[31m#{str}\033[0m"
22
+ end
23
+
24
+ def success(str)
25
+ log "\033[32m#{str}\033[0m"
26
+ end
27
+
28
+ def warning(str)
29
+ log "\033[33m#{str}\033[0m"
30
+ end
31
+
32
+ def notice(str)
33
+ log "\033[1;33m#{str}\033[0m"
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,5 @@
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 @@ module Overcommit
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 @@ module Overcommit
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 @@ module Overcommit
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
@@ -1,8 +1,6 @@
1
1
  module Overcommit
2
2
  module Utils
3
3
  class << self
4
- include ConsoleMethods
5
-
6
4
  @@hooks = []
7
5
 
8
6
  def register_hook(hook)
@@ -20,7 +18,7 @@ module Overcommit
20
18
  def load_hooks
21
19
  require File.expand_path("../hooks/#{hook_name}", __FILE__)
22
20
  rescue LoadError
23
- error "No hook definition found for #{hook_name}"
21
+ log.error "No hook definition found for #{hook_name}"
24
22
  exit 1
25
23
  end
26
24
 
@@ -55,6 +53,12 @@ module Overcommit
55
53
  @modified_files ||=
56
54
  `git diff --cached --name-only --diff-filter=ACM`.split "\n"
57
55
  end
56
+
57
+ private
58
+
59
+ def log
60
+ Logger.instance
61
+ end
58
62
  end
59
63
  end
60
64
  end
@@ -1,3 +1,3 @@
1
1
  module Overcommit
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -33,13 +33,13 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - lib/overcommit/cli.rb
35
35
  - lib/overcommit/configuration.rb
36
- - lib/overcommit/console_methods.rb
37
36
  - lib/overcommit/errors.rb
38
37
  - lib/overcommit/git_hook.rb
39
38
  - lib/overcommit/hook_specific_check.rb
40
39
  - lib/overcommit/hooks/commit_msg.rb
41
40
  - lib/overcommit/hooks/pre_commit.rb
42
41
  - lib/overcommit/installer.rb
42
+ - lib/overcommit/logger.rb
43
43
  - lib/overcommit/plugins/commit_msg/change_id.rb
44
44
  - lib/overcommit/plugins/commit_msg/release_note.rb
45
45
  - lib/overcommit/plugins/commit_msg/russian_novel.rb
@@ -1,23 +0,0 @@
1
- module Overcommit
2
- module ConsoleMethods
3
- def bold(str)
4
- puts "\033[1;37m#{str}\033[0m"
5
- end
6
-
7
- def error(str)
8
- puts "\033[31m#{str}\033[0m"
9
- end
10
-
11
- def success(str)
12
- puts "\033[32m#{str}\033[0m"
13
- end
14
-
15
- def warning(str)
16
- puts "\033[33m#{str}\033[0m"
17
- end
18
-
19
- def notice(str)
20
- puts "\033[1;33m#{str}\033[0m"
21
- end
22
- end
23
- end