rabbitt-githooks 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rubocop.yml +73 -0
  4. data/Gemfile +21 -0
  5. data/Gemfile.lock +45 -0
  6. data/LICENSE.txt +339 -0
  7. data/README.md +4 -0
  8. data/Rakefile +19 -0
  9. data/bin/githooks +15 -0
  10. data/bin/githooks-runner +17 -0
  11. data/hooks/commit-messages.rb +29 -0
  12. data/hooks/formatting.rb +53 -0
  13. data/lib/githooks.rb +89 -0
  14. data/lib/githooks/action.rb +150 -0
  15. data/lib/githooks/cli.rb +93 -0
  16. data/lib/githooks/commands/config.rb +107 -0
  17. data/lib/githooks/core_ext.rb +23 -0
  18. data/lib/githooks/core_ext/array.rb +3 -0
  19. data/lib/githooks/core_ext/array/extract_options.rb +5 -0
  20. data/lib/githooks/core_ext/array/min_max.rb +37 -0
  21. data/lib/githooks/core_ext/array/select_with_index.rb +13 -0
  22. data/lib/githooks/core_ext/numbers.rb +1 -0
  23. data/lib/githooks/core_ext/numbers/infinity.rb +19 -0
  24. data/lib/githooks/core_ext/pathname.rb +27 -0
  25. data/lib/githooks/core_ext/process.rb +7 -0
  26. data/lib/githooks/core_ext/string.rb +3 -0
  27. data/lib/githooks/core_ext/string/git_option_path_split.rb +6 -0
  28. data/lib/githooks/core_ext/string/inflections.rb +67 -0
  29. data/lib/githooks/core_ext/string/strip_empty_lines.rb +9 -0
  30. data/lib/githooks/error.rb +10 -0
  31. data/lib/githooks/hook.rb +159 -0
  32. data/lib/githooks/repository.rb +152 -0
  33. data/lib/githooks/repository/config.rb +170 -0
  34. data/lib/githooks/repository/diff_index_entry.rb +80 -0
  35. data/lib/githooks/repository/file.rb +125 -0
  36. data/lib/githooks/repository/limiter.rb +55 -0
  37. data/lib/githooks/runner.rb +317 -0
  38. data/lib/githooks/section.rb +98 -0
  39. data/lib/githooks/system_utils.rb +109 -0
  40. data/lib/githooks/terminal_colors.rb +63 -0
  41. data/lib/githooks/version.rb +22 -0
  42. data/rabbitt-githooks.gemspec +49 -0
  43. data/thoughts.txt +56 -0
  44. metadata +175 -0
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+ require 'pathname'
3
+ require 'open3'
4
+ require 'ostruct'
5
+ require 'shellwords'
6
+
7
+ module GitHooks
8
+ module SystemUtils
9
+ def which(name)
10
+ find_bin(name).first
11
+ end
12
+ module_function :which
13
+
14
+ def find_bin(name)
15
+ # rubocop:disable MultilineBlockChain, Blocks
16
+ ENV['PATH'].split(/:/).collect {
17
+ |path| Pathname.new(path) + name.to_s
18
+ }.select { |path|
19
+ path.exist? && path.executable?
20
+ }.collect(&:to_s)
21
+ # rubocop:enable MultilineBlockChain, Blocks
22
+ end
23
+ module_function :find_bin
24
+
25
+ def with_path(path, &block)
26
+ fail ArgumentError, 'Missing required block' unless block_given?
27
+ begin
28
+ cwd = Dir.getwd
29
+ Dir.chdir path
30
+ yield path
31
+ ensure
32
+ Dir.chdir cwd
33
+ end
34
+ end
35
+ module_function :with_path
36
+
37
+ def quiet(&block)
38
+ od, ov = GitHooks.debug, GitHooks.verbose
39
+ GitHooks.debug, GitHooks.verbose = false, false
40
+ yield
41
+ ensure
42
+ GitHooks.debug, GitHooks.verbose = od, ov
43
+ end
44
+ module_function :quiet
45
+
46
+ class Command
47
+ include Shellwords
48
+
49
+ attr_reader :aliases, :path, :name
50
+ def initialize(name, options = {})
51
+ @name = name
52
+ @path = options.delete(:path) || SystemUtils.which(name)
53
+
54
+ @aliases = options.delete(:aliases) || []
55
+ @aliases << name
56
+ @aliases.collect! { |_alias| normalize(_alias) }
57
+ @aliases.uniq!
58
+ end
59
+
60
+ def command_path
61
+ path || name.to_s
62
+ end
63
+
64
+ def build_command(args, options = {})
65
+ change_to_path = options['path'] || options[:path]
66
+
67
+ args = [args].flatten
68
+ args.collect! { |arg| arg.is_a?(Repository::File) ? arg.path.to_s : arg }
69
+ args.collect!(&:to_s)
70
+
71
+ command = shelljoin([command_path] | args)
72
+ command = ("cd #{shellescape(change_to_path.to_s)} ; " + command) unless change_to_path.nil?
73
+ command
74
+ end
75
+
76
+ def execute(*args, &block) # rubocop:disable MethodLength, CyclomaticComplexity
77
+ options = args.extract_options
78
+ strip_empty_lines = !!options.delete(:strip_empty_lines)
79
+
80
+ command = build_command(args, options)
81
+ result = OpenStruct.new(output: nil, error: nil, status: nil).tap do |r|
82
+ puts "#{Dir.getwd} $ #{command}" if GitHooks.debug
83
+
84
+ r.output, r.error, r.status = if RUBY_ENGINE == 'jruby'
85
+ _, o, e, t = Open3.popen3('/usr/bin/env', 'sh', '-c', command)
86
+ [o.read, e.read, t.value]
87
+ else
88
+ Open3.capture3(command)
89
+ end
90
+
91
+ if strip_empty_lines
92
+ r.output = r.output.strip_empty_lines!
93
+ r.error = r.error.strip_empty_lines!
94
+ end
95
+ end
96
+
97
+ puts result.inspect if GitHooks.debug
98
+
99
+ block_given? ? yield(result) : result
100
+ end
101
+ alias_method :call, :execute
102
+
103
+ def normalize(name)
104
+ name.to_s.gsub(/[^a-z_]+/, '_')
105
+ end
106
+ private :normalize
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright (C) 2013 Carl P. Corliss
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along
16
+ with this program; if not, write to the Free Software Foundation, Inc.,
17
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ =end
19
+
20
+ module GitHooks
21
+ module TerminalColors
22
+ NORMAL = "\033[0;0"
23
+
24
+ REGEX_COLOR_MAP = {
25
+ /(black|gr[ae]y)/ => 30,
26
+ /red/ => 31,
27
+ /green/ => 32,
28
+ /yellow/ => 33,
29
+ /blue/ => 34,
30
+ /(magenta|purple)/ => 35,
31
+ /cyan/ => 36,
32
+ /white/ => 37
33
+ }
34
+
35
+ def color(name)
36
+ return '' unless $stdout.tty? && $stderr.tty?
37
+ light = !!name.match(/(light|bright)/) ? '1' : '0'
38
+ blink = !!name.match(/blink/) ? ';5' : ''
39
+
40
+ color_code = REGEX_COLOR_MAP.find { |key, code| name =~ key }
41
+ color_code = color_code ? color_code.last : NORMAL
42
+
43
+ "\033[#{light}#{blink};#{color_code}m"
44
+ end
45
+ module_function :color
46
+
47
+ ['light', 'bright', 'dark', ''].each do |shade|
48
+ ['blinking', ''].each do |style|
49
+ %w(black gray red green yellow blue magenta purple cyan white).each do |color|
50
+ name1 = "color_#{style}_#{shade}_#{color}".gsub(/(^_+|_+$)/, '').gsub(/_{2,}/, '_')
51
+ name2 = "color_#{style}_#{shade}#{color}".gsub(/(^_+|_+$)/, '').gsub(/_{2,}/, '_')
52
+ [name1, name2].each do |name|
53
+ unless const_defined? name.upcase
54
+ const_set(name.upcase, color(name))
55
+ define_method(name) { |text| "#{color(name)}#{text}#{color(:normal)}" }
56
+ module_function name.to_sym
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright (C) 2013 Carl P. Corliss
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along
16
+ with this program; if not, write to the Free Software Foundation, Inc.,
17
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ =end
19
+
20
+ module GitHooks
21
+ VERSION = '1.2.7'
22
+ end
@@ -0,0 +1,49 @@
1
+ =begin
2
+ Copyright (C) 2013 Carl P. Corliss
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along
15
+ with this program; if not, write to the Free Software Foundation, Inc.,
16
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+ =end
18
+
19
+ # coding: utf-8
20
+
21
+ lib = File.expand_path('../lib', __FILE__)
22
+ $:.unshift(lib) unless $:.include?(lib)
23
+ require 'githooks'
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = "rabbitt-githooks"
27
+ spec.version = GitHooks::VERSION
28
+ spec.authors = GitHooks::AUTHOR.scan(/,?\s*([^<]+)<([^>]+)>\s*,?/).collect(&:first).collect(&:strip)
29
+ spec.email = GitHooks::AUTHOR.scan(/,?\s*([^<]+)<([^>]+)>\s*,?/).collect(&:last).collect(&:strip)
30
+ spec.description = "GitHooker provides a framework for building tests that can be used with git hooks"
31
+ spec.homepage = "http://github.com/rabbitt/githooks"
32
+ spec.summary = "framework for building git hooks tests"
33
+ spec.license = "GPLv2"
34
+ spec.rubygems_version = "2.0.14"
35
+
36
+ spec.files = `git ls-files`.split($/)
37
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
38
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
39
+ spec.require_paths = ["lib"]
40
+ spec.extra_rdoc_files = ["README.md", 'LICENSE.txt']
41
+
42
+ spec.add_dependency 'colorize', '~> 0.5.8'
43
+ spec.add_dependency 'thor', '~> 0.18'
44
+
45
+ spec.add_development_dependency 'rake', '~> 10.1'
46
+ spec.add_development_dependency 'rspec', '~> 2.14'
47
+ spec.add_development_dependency 'bundler', '~> 1.3'
48
+ spec.add_development_dependency 'rubocop', '~> 0.18'
49
+ end
data/thoughts.txt ADDED
@@ -0,0 +1,56 @@
1
+
2
+ githook config [--global] [--hook <hookname>] get <var>
3
+ githook config [--global] [--hook <hookname>] set <var> <value>
4
+ githook config [--global] [--hook <hookname>] unset <var> [<value>]
5
+
6
+ variables:
7
+ path: <path string>
8
+ - the path to the tests to load for the given repository or globally. Can not be set if script is set.
9
+
10
+ script: <path string>
11
+ - the path to the script to execute when the given hook(s) are run.
12
+
13
+ pre-run-execute: Array<path string>
14
+ - a list of executables to run before the tests run
15
+
16
+ post-run-execute: Array<path string>
17
+ - a list of executables to run after the tests run
18
+
19
+ githook config [--global] show
20
+ - show the current githook configuration (global or repository)
21
+
22
+ githook list [--hook <hook1,hook2,hookN>]
23
+ -- lists tests for the given hook(s), or all hooks if none specified
24
+
25
+ githook attach [--hook <hook1,hookN>] [--script <path> | --path <path>]
26
+ -- attaches the listed hooks (or all if none specified) to the githook runner
27
+ optionally sets the script XOR path
28
+
29
+ githook dettach [--hook <hook1,hookN>]
30
+ -- detaches the listed hooks, or all hooks if none specified
31
+
32
+ githooks run [--hook <hook1,hookN>] [--[un]staged] [--args -- one two three ... fifty]
33
+ -- runs the selected hooks (or pre-commit, if none specified) passing
34
+ the argument list to the script
35
+
36
+
37
+ ----
38
+
39
+ GitHook::Hook.register 'pre-commit' do
40
+ command ruby, path: /usr/local/bin/ruby
41
+
42
+ section 'Syntax Checks' do
43
+ test 'Ruby Syntax' do
44
+ limit(:type).to :modified, :added
45
+ limit(:path).to %r{\.rb$}
46
+
47
+ on_each_file { |file| ruby '-c', file.path }
48
+ end
49
+ end
50
+ end
51
+
52
+ -- repository's .git/config file --
53
+
54
+ [githooks]
55
+ tests_path = /foo/lib
56
+ loader_path = /foo/bin/runner.sh
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbitt-githooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.7
5
+ platform: ruby
6
+ authors:
7
+ - Carl P. Corliss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.18'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.18'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.18'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.18'
97
+ description: GitHooker provides a framework for building tests that can be used with
98
+ git hooks
99
+ email:
100
+ - rabbitt@gmail.com
101
+ executables:
102
+ - githooks
103
+ - githooks-runner
104
+ extensions: []
105
+ extra_rdoc_files:
106
+ - README.md
107
+ - LICENSE.txt
108
+ files:
109
+ - ".gitignore"
110
+ - ".rubocop.yml"
111
+ - Gemfile
112
+ - Gemfile.lock
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bin/githooks
117
+ - bin/githooks-runner
118
+ - hooks/commit-messages.rb
119
+ - hooks/formatting.rb
120
+ - lib/githooks.rb
121
+ - lib/githooks/action.rb
122
+ - lib/githooks/cli.rb
123
+ - lib/githooks/commands/config.rb
124
+ - lib/githooks/core_ext.rb
125
+ - lib/githooks/core_ext/array.rb
126
+ - lib/githooks/core_ext/array/extract_options.rb
127
+ - lib/githooks/core_ext/array/min_max.rb
128
+ - lib/githooks/core_ext/array/select_with_index.rb
129
+ - lib/githooks/core_ext/numbers.rb
130
+ - lib/githooks/core_ext/numbers/infinity.rb
131
+ - lib/githooks/core_ext/pathname.rb
132
+ - lib/githooks/core_ext/process.rb
133
+ - lib/githooks/core_ext/string.rb
134
+ - lib/githooks/core_ext/string/git_option_path_split.rb
135
+ - lib/githooks/core_ext/string/inflections.rb
136
+ - lib/githooks/core_ext/string/strip_empty_lines.rb
137
+ - lib/githooks/error.rb
138
+ - lib/githooks/hook.rb
139
+ - lib/githooks/repository.rb
140
+ - lib/githooks/repository/config.rb
141
+ - lib/githooks/repository/diff_index_entry.rb
142
+ - lib/githooks/repository/file.rb
143
+ - lib/githooks/repository/limiter.rb
144
+ - lib/githooks/runner.rb
145
+ - lib/githooks/section.rb
146
+ - lib/githooks/system_utils.rb
147
+ - lib/githooks/terminal_colors.rb
148
+ - lib/githooks/version.rb
149
+ - rabbitt-githooks.gemspec
150
+ - thoughts.txt
151
+ homepage: http://github.com/rabbitt/githooks
152
+ licenses:
153
+ - GPLv2
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.2.2
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: framework for building git hooks tests
175
+ test_files: []