rabbitt-githooks 1.2.7 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3e40cb17024ec5370eddeb7bb319bba3c375584b
4
- data.tar.gz: 2c6e605e38d294cbc80bbbb6aa7b5b8b1e7bee46
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmVlMTFhYmNmYjA2YmM3NWJiMTA1YWNhMjk2MmE5ODhmZjQwZjZlYQ==
5
+ data.tar.gz: !binary |-
6
+ ZDQ3ZGMwYTI1MGY3NDc3ZmM2NTk0NGJkMjg1NjBlYWU5NTgyN2MwOQ==
5
7
  SHA512:
6
- metadata.gz: fb6e899b1b945fca2df1ed0651f381359ba49c16868db5e19c96a0e052b33e5cf1fc8dead531aa571fbee00df546154740fbb264fb220ee3c4b770ebe7142a25
7
- data.tar.gz: 5d713409381fe9e06f160f3bec990816f2f81813876ac32a64faf51b9e05e8f41ecc3ba060ca5b98b9d87412e4054b22a31cd3604af3c66b864cf741220548d9
8
+ metadata.gz: !binary |-
9
+ NDQ0YzkzNWQ4Yjc3NjQwYWYzNWQ5ZjIwZmM1MGZlOTQxYTJhNDFiODhjMTNl
10
+ ZWVkOGNmOTJhZmNhZGI1NjQ2ZDYxMTNiYzU5ZTA0MTFhMTUwODhkMmQ4MWZk
11
+ NzExZTY3MDQyNzAxMzNhMzA4MzU2YTdmOGE5YmUwOWQ1Y2E5YTI=
12
+ data.tar.gz: !binary |-
13
+ NDZiMTMyZDllMDZjZmE3Yjg2ZTcyODJiMWJkNDAzYjAxNDRjYjViYWY2ZjBm
14
+ YWRkNmY5MTc2ZGEyMGRlNDRiZmRiMjAzOGMyOGE0MTk5NDFhMmFlNDliODdj
15
+ N2I0MzI4NDY5MTkxNGFmMDhiMWIzZDFmMDA5MWE5NWVlYmFiY2I=
File without changes
@@ -3,11 +3,11 @@ require 'githooks'
3
3
  RUBY_FILE_REGEXP = %r{^((app|lib)/.+\.rb|bin/.+)$}.freeze
4
4
 
5
5
  GitHooks::Hook.register 'pre-commit' do
6
- commands 'scss-lint', :ruby, :rubocop
6
+ commands :ruby, :rubocop
7
7
 
8
- section 'Standards' do
8
+ section 'Standards' do
9
9
  action 'Validate Ruby Syntax' do
10
- limit(:type).to :modified, :added, :untracked
10
+ limit(:type).to :modified, :added, :untracked, :tracked
11
11
  limit(:path).to RUBY_FILE_REGEXP
12
12
 
13
13
  on_each_file do |file|
@@ -16,16 +16,16 @@ GitHooks::Hook.register 'pre-commit' do
16
16
  end
17
17
 
18
18
  action 'Validate Ruby Standards' do
19
- limit(:type).to :modified, :added, :untracked
19
+ limit(:type).to :modified, :added, :untracked, :tracked
20
20
  limit(:path).to RUBY_FILE_REGEXP
21
21
 
22
22
  on_all_files do |files|
23
- rubocop '-D', '--format', 'clang', files, strip_empty_lines: true
23
+ rubocop '-D', '--format', 'clang', files.collect(&:path), strip_empty_lines: true
24
24
  end
25
25
  end
26
26
 
27
27
  action 'No Leading Tabs in Ruby files' do
28
- limit(:type).to :modified, :added, :untracked
28
+ limit(:type).to :modified, :added, :untracked, :tracked
29
29
  limit(:path).to RUBY_FILE_REGEXP
30
30
 
31
31
  on_each_file do |file|
@@ -40,14 +40,5 @@ GitHooks::Hook.register 'pre-commit' do
40
40
  end.empty?
41
41
  end
42
42
  end
43
-
44
- action 'Validate CSS Syntax' do
45
- limit(:type).to :modified, :added, :untracked
46
- limit(:path).to %r{^(app|lib)/.+css$}
47
-
48
- on_all_files do |files|
49
- scss_lint files.collect(&:path)
50
- end
51
- end
52
43
  end
53
44
  end
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
- Includes:
2
+ Include:
3
3
  - Rakefile
4
- Excludes:
4
+ Exclude:
5
5
  - test.rb
6
6
  - bin/**
7
7
 
@@ -34,9 +34,9 @@ RegexpLiteral:
34
34
  DotPosition:
35
35
  Enabled: false
36
36
 
37
- MethodLength:
37
+ Style/MethodLength:
38
38
  CountComments: false
39
- Max: 15
39
+ Max: 20
40
40
 
41
41
  ParameterLists:
42
42
  Max: 5
@@ -71,3 +71,17 @@ EmptyLinesAroundAccessModifier:
71
71
  EndAlignment:
72
72
  AlignWith: variable
73
73
 
74
+ Style/DoubleNegation:
75
+ Enabled: false
76
+
77
+ Style/PercentLiteralDelimiters:
78
+ Enabled: false
79
+
80
+ Style/FormatString:
81
+ Enabled: false
82
+
83
+ Lint/UnusedMethodArgument:
84
+ Enabled: false
85
+
86
+ Style/EachWithObject:
87
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,36 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbitt-githooks (1.2.7)
4
+ rabbitt-githooks (1.3.0)
5
5
  colorize (~> 0.5.8)
6
6
  thor (~> 0.18)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- ast (1.1.0)
11
+ ast (2.0.0)
12
12
  colorize (0.5.8)
13
13
  diff-lcs (1.2.5)
14
14
  json (1.8.1)
15
- parser (2.1.7)
16
- ast (~> 1.1)
15
+ parser (2.1.9)
16
+ ast (>= 1.1, < 3.0)
17
17
  slop (~> 3.4, >= 3.4.5)
18
18
  powerpack (0.0.9)
19
19
  rainbow (2.0.0)
20
- rake (10.1.1)
21
- rspec (2.14.1)
22
- rspec-core (~> 2.14.0)
23
- rspec-expectations (~> 2.14.0)
24
- rspec-mocks (~> 2.14.0)
25
- rspec-core (2.14.8)
26
- rspec-expectations (2.14.5)
20
+ rake (10.3.2)
21
+ rspec (2.99.0)
22
+ rspec-core (~> 2.99.0)
23
+ rspec-expectations (~> 2.99.0)
24
+ rspec-mocks (~> 2.99.0)
25
+ rspec-core (2.99.1)
26
+ rspec-expectations (2.99.1)
27
27
  diff-lcs (>= 1.1.3, < 2.0)
28
- rspec-mocks (2.14.6)
29
- rubocop (0.18.1)
28
+ rspec-mocks (2.99.1)
29
+ rubocop (0.23.0)
30
30
  json (>= 1.7.7, < 2)
31
- parser (~> 2.1.3)
31
+ parser (~> 2.1.9)
32
32
  powerpack (~> 0.0.6)
33
33
  rainbow (>= 1.99.1, < 3.0)
34
+ ruby-progressbar (~> 1.4)
35
+ ruby-lint (2.0.1)
36
+ parser (~> 2.1, >= 2.1.1)
37
+ slop (~> 3.4, >= 3.4.7)
38
+ ruby-progressbar (1.5.1)
34
39
  slop (3.5.0)
35
40
  thor (0.19.1)
36
41
 
@@ -43,3 +48,4 @@ DEPENDENCIES
43
48
  rake (~> 10.1)
44
49
  rspec (~> 2.14)
45
50
  rubocop (~> 0.18)
51
+ ruby-lint (~> 2.0.1)
data/README.md CHANGED
@@ -1,4 +1,110 @@
1
- githooks
2
- ========
1
+ rabbitt-githooks
2
+ ================
3
+
4
+ # GitHooks
5
+
6
+ Githooks provides a framework for creating standard pre-commit and commit-msg hooks for your git repository. These hooks run
7
+ client side (not on a remote server), and can be used to validate your commits (actual deltas and commit messages), reducing
8
+ the possibility of broken commits (or bad commit messages) making it into your repository.
9
+
10
+ ## Installation
11
+
12
+ 1. gem install rabbitt-githooks
13
+ 2. add rabbitt-githooks to the development group of your project's Gemfile
14
+ 2. setup your `project` to use githooks:
15
+
16
+ ```
17
+ cd /path/to/project
18
+ mkdir commit-hooks
19
+ githooks attach --path /path/to/commit-hooks
20
+ ```
21
+
22
+ With the hooks installed, you can run the checks against your staged or unstaged deltas before you commit, or just commit
23
+ your deltas and have the checks run automatically.
24
+
25
+ ## Creating Tests
26
+
27
+ ### Tests Path
28
+
29
+ All tests should be located under the path that was defined when attaching githooks to your project. In the following
30
+ examples we'll assume a project root of `/work/projects/railsapp` and a hooks path of `/work/projects/railsapp/.hooks`.
31
+
32
+ ### Registration
33
+
34
+ All hooks must be registered via ```GitHooks::Hook.register <PHASE>, <BLOCK>```
35
+
36
+ ### Commands
37
+ ### Sections
38
+ ### Actions
39
+ #### Limiters (aka filters)
40
+ #### on* (action executors)
41
+
42
+ <dl>
43
+ <dt><strong>on_each_file(&block)</strong></dt>
44
+ <dd></dd>
45
+ <dt><strong>on_all_files(&block)</strong></dt>
46
+ <dd></dd>
47
+ <dt><strong>on_argv(&block)</strong></dt>
48
+ <dd></dd>
49
+ </dl>
50
+
51
+ #### pre-commit vs commit-msg
52
+
53
+ ## Command-Line Usage
54
+
55
+ ### Listing Attached Tests
56
+ To view the list of checks currently attached to your repository:
57
+
58
+ ```
59
+ $ cd /path/to/cms ; githooks list
60
+
61
+ Main Testing Library with Tests (in execution order):
62
+ Tests loaded from:
63
+ /Users/jdoe/work/repos/myproject/commit-hooks
64
+
65
+ Phase PreCommit:
66
+ 1: Standards
67
+ 1: Validate Ruby Syntax
68
+ Limiter 1: :type -> [:modified, :added]
69
+ Limiter 2: :path -> /^(app|lib)\/.+\.rb$/
70
+ 2: No Leading Spaces in Ruby files
71
+ Limiter 1: :type -> [:modified, :added]
72
+ Limiter 2: :path -> /^(app|lib)\/.+\.rb$/
73
+ 3: Validate CSS Syntax
74
+ Limiter 1: :type -> [:modified, :added]
75
+ Limiter 2: :path -> /^(app|lib)\/.+css$/
76
+ Phase CommitMsg:
77
+ 1: Commit Message
78
+ 1: Message Length > 5 characters
79
+ 2: Verify no simple commit messages
80
+ ```
81
+
82
+ ### Manually Running Tests
83
+
84
+ To run the pre-commit hook on unstaged deltas, run the following command:
85
+
86
+ ```
87
+ $ cd /path/to/cms ; githooks exec --unstaged
88
+ ===== PreCommit :: Standards =====
89
+ 1. [ X ] Validate Ruby Syntax
90
+ X app/models/element.rb:245: syntax error, unexpected keyword_end, expecting end-of-input
91
+ 2. [ X ] No Leading Spaces in Ruby files
92
+ X app/models/element.rb:4: _______# something here
93
+ X app/models/element.rb:5: __a = 1
94
+ X app/models/element.rb:6: ____
95
+ 3. [ X ] Validate CSS Syntax
96
+ X app/assets/stylesheets/application.css.scss:4 [W] Prefer single quoted strings
97
+ X app/assets/stylesheets/application.css.scss:8 [W] Use // comments everywhere
98
+ X app/assets/stylesheets/application.css.scss:10 [W] Line should be indented 1 spaces, but was indented 2 spaces
99
+ X app/assets/stylesheets/application.css.scss:19 [W] Each selector in a comma sequence should be on its own line
100
+ X app/assets/stylesheets/application.css.scss:20 [W] Properties should be sorted in alphabetical order, with vendor-prefixed extensions before the standardized CSS property
101
+ X app/assets/stylesheets/application.css.scss:22 [W] `0.75` should be written without a leading zero as `.75`
102
+ X app/assets/stylesheets/application.css.scss:23 [W] `border: 0;` is preferred over `border: none;`
103
+ X app/assets/stylesheets/elements.css.scss:35 [W] Commas in function arguments should be followed by a single space
104
+ X app/assets/stylesheets/elements.css.scss:35 [W] Colon after property should be followed by 1 space instead of 0 spaces
105
+ X app/assets/stylesheets/elements.css.scss:35 [W] Commas in function arguments should be followed by a single space
106
+
107
+ Commit failed due to errors listed above.
108
+ Please fix and attempt your commit again.
109
+ ```
3
110
 
4
- GitHooks Gem
data/bin/githooks CHANGED
@@ -12,4 +12,4 @@ rescue GitHooks::Error => e
12
12
  exit 1
13
13
  end
14
14
 
15
- exit 0
15
+ exit 0
data/bin/githooks-runner CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # rubocop:disable Style/FileName
2
3
 
3
4
  if ENV['GITHOOKS_DEV']
4
5
  $:.unshift(File.expand_path(File.join(File.expand_path(__FILE__), '/../../lib')))
data/lib/githooks.rb CHANGED
@@ -25,17 +25,17 @@ require 'githooks/version'
25
25
  module GitHooks
26
26
  AUTHOR = 'Carl P. Corliss <rabbitt@gmail.com>'
27
27
 
28
- autoload :Config, 'githooks/config'
29
- autoload :CommandRunner, 'githooks/command'
30
- autoload :Command, 'githooks/command'
31
- autoload :CLI, 'githooks/cli'
32
- autoload :Hook, 'githooks/hook'
33
- autoload :Section, 'githooks/section'
34
- autoload :Action, 'githooks/action'
35
- autoload :Repository, 'githooks/repository'
36
- autoload :Runner, 'githooks/runner'
37
- autoload :SystemUtils, 'githooks/system_utils'
38
- autoload :TerminalColors, 'githooks/terminal_colors'
28
+ autoload :Config, 'githooks/config'
29
+ autoload :CommandRunner, 'githooks/command'
30
+ autoload :Command, 'githooks/command'
31
+ autoload :CLI, 'githooks/cli'
32
+ autoload :Hook, 'githooks/hook'
33
+ autoload :Section, 'githooks/section'
34
+ autoload :Action, 'githooks/action'
35
+ autoload :Repository, 'githooks/repository'
36
+ autoload :Runner, 'githooks/runner'
37
+ autoload :SystemUtils, 'githooks/system_utils'
38
+ autoload :TerminalColors, 'githooks/terminal_colors'
39
39
 
40
40
  class << self
41
41
  attr_reader :debug, :verbose, :ignore_script
@@ -19,25 +19,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
19
19
 
20
20
  require 'stringio'
21
21
  require 'open3'
22
+ require 'set'
22
23
 
23
24
  module GitHooks
24
- class Action
25
+ class Action # rubocop:disable Style/ClassLength
25
26
  include TerminalColors
26
27
 
27
- attr_reader :title, :section, :on, :limiters, :success, :errors, :warnings
28
+ attr_reader :title, :section, :on, :limiters
29
+ attr_reader :success, :errors, :warnings, :benchmark
28
30
  private :section, :on
29
31
  alias_method :success?, :success
30
32
 
31
33
  def initialize(title, section, &block)
32
34
  fail ArgumentError, 'Missing required block' unless block_given?
33
35
 
34
- @title = title
35
- @section = section
36
- @on = nil
37
- @limiters = []
38
- @success = true
39
- @errors = []
40
- @warnings = []
36
+ @title = title
37
+ @section = section
38
+ @on = nil
39
+ @limiters = Set.new
40
+ @success = true
41
+ @errors = []
42
+ @warnings = []
43
+ @benchmark = 0
41
44
 
42
45
  instance_eval(&block)
43
46
 
@@ -73,6 +76,7 @@ module GitHooks
73
76
  begin
74
77
  running!
75
78
  $stdout, $stderr = warnings, errors
79
+ time_start = Time.now
76
80
  @success &= @on.call
77
81
  rescue => error
78
82
  errors.puts "Exception thrown during action call: #{error.class.name}: #{error.message}"
@@ -87,6 +91,7 @@ module GitHooks
87
91
 
88
92
  @success = false
89
93
  ensure
94
+ @benchmark = Time.now - time_start
90
95
  @errors, @warnings = [errors, warnings].collect do |io|
91
96
  io.rewind
92
97
  io.read.split(/\n/)
@@ -107,8 +112,8 @@ module GitHooks
107
112
 
108
113
  # DSL Methods
109
114
 
110
- def limit(what)
111
- Repository::Limiter.new(what).tap do |limiter|
115
+ def limit(type)
116
+ (find_limiter(type) || Repository::Limiter.new(type)).tap do |limiter|
112
117
  @limiters << limiter
113
118
  end
114
119
  end
@@ -131,6 +136,10 @@ module GitHooks
131
136
 
132
137
  private
133
138
 
139
+ def find_limiter(type)
140
+ @limiters.select { |l| l.type == type }.first
141
+ end
142
+
134
143
  def run_command(command, *args, &block)
135
144
  options = args.extract_options
136
145
  prefix = options.delete(:prefix_output)
data/lib/githooks/cli.rb CHANGED
@@ -59,13 +59,14 @@ module GitHooks
59
59
  Runner.list(options['repo'])
60
60
  end
61
61
 
62
- # githooks run [--hook <hook1,hookN>] [--[un]staged] [--args -- one two three ... fifty]
62
+ # githooks execute [--[no-]staged] [--tracked] [--untracked] [--args -- one two three ...]
63
63
  # -- runs the selected hooks (or pre-commit, if none specified) passing
64
64
  # the argument list to the script
65
65
 
66
66
  desc :execute, 'Runs the selected hooks, passing the argument list to the script'
67
- method_option :unstaged, aliases: '-U', type: :boolean, desc: 'test unstaged files', default: false
68
- method_option :untracked, aliases: '-T', type: :boolean, desc: 'test unstaged files', default: false
67
+ method_option :staged, aliases: '-S', type: :boolean, desc: 'test staged files', default: nil
68
+ method_option :tracked, aliases: '-A', type: :boolean, desc: 'test all tracked files', default: false
69
+ method_option :untracked, aliases: '-T', type: :boolean, desc: 'test untracked files', default: false
69
70
  method_option :script, aliases: '-s', type: :string, desc: 'Path to script to run', default: nil
70
71
  method_option :path, aliases: '-p', type: :string, desc: 'Path to library of tests', default: nil
71
72
  method_option :repo, aliases: '-r', type: :string, desc: 'Path to repo to run tests on', default: Dir.getwd
@@ -78,11 +79,19 @@ module GitHooks
78
79
  GitHooks.debug = !!options['debug']
79
80
 
80
81
  opts = (options).dup
81
- if opts['untracked'] && !opts['unstaged']
82
- warn %q|--untracked requires --unstaged. Dropping option --untracked...|
83
- opts['untracked'] = false
82
+
83
+ if opts['staged']
84
+ if opts['tracked']
85
+ warn %q|--tracked conflicts with --staged. Dropping --tracked...|
86
+ opts['tracked'] = false
87
+ elsif opts['untracked']
88
+ warn %q|--untracked conflicts with --staged. Dropping --untracked...|
89
+ opts['untracked'] = false
90
+ end
84
91
  end
85
92
 
93
+ opts['staged'] = !(opts['tracked'] || opts['untracked']) if opts['staged'].nil?
94
+
86
95
  GitHooks::Runner.run(opts)
87
96
  end
88
97