git-hooks-helper 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -1 +1 @@
1
- gitt-hooks-helper-*.gem
1
+ git-hooks-helper-*.gem
data/Gemfile.lock CHANGED
@@ -1,30 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-hooks-helper (0.0.1)
5
- rails-erb-check
6
- rails_best_practices
4
+ git-hooks-helper (0.0.2)
7
5
 
8
6
  GEM
9
7
  remote: http://rubygems.org/
10
8
  specs:
11
9
  abstract (1.0.0)
12
- actionpack (3.0.11)
13
- activemodel (= 3.0.11)
14
- activesupport (= 3.0.11)
15
- builder (~> 2.1.2)
16
- erubis (~> 2.6.6)
17
- i18n (~> 0.5.0)
18
- rack (~> 1.2.1)
19
- rack-mount (~> 0.6.14)
20
- rack-test (~> 0.5.7)
21
- tzinfo (~> 0.3.23)
22
- activemodel (3.0.11)
23
- activesupport (= 3.0.11)
24
- builder (~> 2.1.2)
25
- i18n (~> 0.5.0)
26
10
  activesupport (3.0.11)
27
- builder (2.1.2)
28
11
  coderay (0.9.8)
29
12
  colored (1.2)
30
13
  diff-lcs (1.1.3)
@@ -39,13 +22,6 @@ GEM
39
22
  method_source (~> 0.6.7)
40
23
  ruby_parser (>= 2.3.1)
41
24
  slop (~> 2.1.0)
42
- rack (1.2.4)
43
- rack-mount (0.6.14)
44
- rack (>= 1.0.0)
45
- rack-test (0.5.7)
46
- rack (>= 1.0)
47
- rails-erb-check (0.1.0)
48
- actionpack (~> 3.0)
49
25
  rails_best_practices (1.3.0)
50
26
  activesupport
51
27
  colored
@@ -65,7 +41,6 @@ GEM
65
41
  sexp_processor (~> 3.0)
66
42
  sexp_processor (3.0.10)
67
43
  slop (2.1.0)
68
- tzinfo (0.3.31)
69
44
 
70
45
  PLATFORMS
71
46
  ruby
data/README.md CHANGED
@@ -1,15 +1,53 @@
1
- #!/usr/bin/env ruby
1
+ Instalation
2
+ -----------
3
+ gem install git-hooks-helper
2
4
 
3
- require "git-hooks-helper"
5
+ File clasification
6
+ ------------------
4
7
 
5
- GitHooksHelper.results do
6
- do_not_stop_on_warnings
8
+ Most commands use file classes internally or accept type class as a param.
9
+ File type classes and associated file extensions:
7
10
 
8
- check_ruby_syntax
9
- check_erb
10
- check_best_practices
11
- warning_on "WTF?", "binding.pry", "<<<<<<<"
12
- warning_on "console.log", "debugger", {:in => [:js]}
11
+ 1. :rb - .rb .rake .task .prawn
12
+ 2. :js - .js
13
+ 3. :erb - .erb
13
14
 
14
- info "Run rspec tests and have a nice day."
15
- end
15
+ Usage
16
+ -----
17
+ Create your hit hook in .git/hooks directory and make it executable.
18
+
19
+ My example pre-commit hook that i use myself.
20
+ To create such a hook type in console:
21
+
22
+ cd your/project/
23
+ touch .git/hooks/pre-commit
24
+ chmod +x .git/hooks/pre-commit
25
+ vim .git/hooks/pre-commit
26
+
27
+ and paste following code:
28
+
29
+
30
+ ```ruby
31
+ #!/usr/bin/env ruby
32
+
33
+ require "git-hooks-helper"
34
+
35
+ GitHooksHelper.results do
36
+ # fail/pass options
37
+ # stop_on_warnings # makes git commit fail if any warnings are found
38
+ # never_stop # hooks never fails commits
39
+ # list_files # shows list of all changed files
40
+
41
+ # checks
42
+ check_ruby_syntax # errors when ruby syntax has errors
43
+ check_erb # errors when ERB syntax has errors
44
+ check_best_practices # warnings when ruby best practices are violated
45
+ warning_on "WTF?", "binding.pry", "<<<<<<<" # warnings when any of these texts are present in any commited files
46
+ warning_on "console.log", "debugger", {:in => [:js]} # warning when any of these texts are present in JS files
47
+
48
+ # messages
49
+ info "Run rspec tests and have a nice day." # Green text
50
+ notice "Or bad things will happen" # Yellow text
51
+ warn "Cthulhu" # Red text
52
+ end
53
+ ```
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ 1.
2
+ 1. Add project to TravisCI
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "git-hooks-helper"
7
7
  s.version = GitHooksHelper::VERSION
8
8
  s.authors = ["Martynas Margis"]
9
- s.email = []
10
- s.homepage = ""
9
+ s.email = ["no@email.com"]
10
+ s.homepage = "https://github.com/BuGo/git-hooks-helper"
11
11
  s.summary = %q{Small gem to help write simple git hooks}
12
12
  s.description = %q{Gem for creating simple git hooks in ruby.}
13
13
 
@@ -18,6 +18,5 @@ Gem::Specification.new do |s|
18
18
  # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency "rails-erb-check"
22
- s.add_runtime_dependency "rails_best_practices"
21
+ # s.add_runtime_dependency "open3"
23
22
  end
@@ -1,10 +1,11 @@
1
1
  module GitHooksHelper
2
2
  class Git
3
3
  class << self
4
- FILES_TO_WATCH = /(.+\.(e?rb|task|rake|thor|prawn)|[Rr]akefile|[Tt]horfile)/
4
+ FILES_TO_WATCH = /(.+\.(e?rb|task|rake|thor|prawn|haml|coffee)|[Rr]akefile|[Tt]horfile)/
5
5
 
6
6
  def in_index
7
- `git diff-index --name-only --cached HEAD`.split("\n").select{ |file| file =~ FILES_TO_WATCH }.map(&:chomp)
7
+ #`git diff-index --name-only --cached HEAD`.split("\n").select{ |file| file =~ FILES_TO_WATCH }.map(&:chomp)
8
+ `git diff --cached --name-only --diff-filter=AM HEAD`.split("\n").map(&:chomp).select{|file| file =~ FILES_TO_WATCH}
8
9
  end
9
10
  end
10
11
  end
@@ -1,5 +1,6 @@
1
1
  require "git-hooks-helper/result"
2
2
  require "git-hooks-helper/git"
3
+ require "git-hooks-helper/ruby"
3
4
  require "git-hooks-helper/extensions/string"
4
5
  require "open3"
5
6
 
@@ -9,17 +10,31 @@ module GitHooksHelper
9
10
  RB_REGEXP = /\.(rb|rake|task|prawn)\z/
10
11
  ERB_REGEXP = /\.erb\z/
11
12
  JS_REGEXP = /\.js\z/
13
+ HAML_REGEXP = /\.haml\z/
14
+ COFFEE_REGEXP = /\.coffee\z/
15
+
16
+ FILETYPES = {
17
+ rb: RB_REGEXP,
18
+ erb: ERB_REGEXP,
19
+ js: JS_REGEXP,
20
+ haml: HAML_REGEXP,
21
+ coffee: COFFEE_REGEXP
22
+ }
12
23
 
13
24
  RB_WARNING_REGEXP = /[0-9]+:\s+warning:/
25
+ HAML_INVALID_REGEXP = /error/
14
26
  ERB_INVALID_REGEXP = /invalid\z/
15
27
  COLOR_REGEXP = /\e\[(\d+)m/
16
28
 
17
29
  # Set this to true if you want warnings to stop your commit
18
30
  def initialize(&block)
19
- @compiler_ruby = `which ruby`.strip
31
+ @ruby = GitHooksHelper::Ruby.new
32
+ @debug = false
20
33
 
21
34
  @result = GitHooksHelper::Result.new(false)
22
- @changed_ruby_files = GitHooksHelper::Git.in_index
35
+ @changed_files = GitHooksHelper::Git.in_index
36
+ debug("changed files")
37
+ debug @changed_files
23
38
 
24
39
  instance_eval(&block) if block
25
40
 
@@ -54,6 +69,14 @@ module GitHooksHelper
54
69
  end
55
70
  end
56
71
 
72
+ def start_debug
73
+ @debug = true
74
+ end
75
+
76
+ def stop_debug
77
+ @debug = false
78
+ end
79
+
57
80
  def stop_on_warnings
58
81
  @result.stop_on_warnings = true
59
82
  end
@@ -67,25 +90,37 @@ module GitHooksHelper
67
90
  end
68
91
 
69
92
  def list_files(filetypes = [:all])
93
+ puts "--- Listing files of type: #{filetypes}"
70
94
  each_changed_file(filetypes) do |file|
71
95
  puts file
72
96
  end
97
+ puts "--- End of list"
73
98
  end
74
99
 
75
100
  def each_changed_file(filetypes = [:all])
101
+ filetypes = [filetypes] unless filetypes.class == Array
76
102
  if @result.continue?
77
- @changed_ruby_files.each do |file|
78
- unless filetypes.include?(:all)
79
- next unless (filetypes.include?(:rb) and file =~ RB_REGEXP) or (filetypes.include?(:erb) and file =~ ERB_REGEXP) or (filetypes.include?(:js) and file =~ JS_REGEXP)
80
- end
103
+ debug("Can continue")
104
+ @changed_files.each do |file|
105
+ next unless file_matches_filetypes?(file, filetypes)
81
106
  yield file if File.readable?(file)
82
107
  end
108
+ else
109
+ debug("Cannot continue")
110
+ end
111
+ end
112
+
113
+ def file_matches_filetypes?(file, filetypes)
114
+ return true if filetypes.include?(:all)
115
+ filetypes.each do |type|
116
+ return true if file =~ FILETYPES[type]
83
117
  end
118
+ return false
84
119
  end
85
120
 
86
121
  def check_ruby_syntax
87
122
  each_changed_file([:rb]) do |file|
88
- Open3.popen3("#{@compiler_ruby} -wc #{file}") do |stdin, stdout, stderr|
123
+ Open3.popen3(GitHooksHelper::Ruby.check_syntax(file)) do |stdin, stdout, stderr|
89
124
  stderr.read.split("\n").each do |line|
90
125
  line =~ RB_WARNING_REGEXP ? @result.warnings << line : @result.errors << line
91
126
  end
@@ -101,10 +136,17 @@ module GitHooksHelper
101
136
  end
102
137
  end
103
138
 
139
+ def check_haml
140
+ each_changed_file([:haml]) do |file|
141
+ popen3("haml --check #{file}") do |stdin, stdout, stderr|
142
+ @result.errors.concat stderr.read.split("\n").map{|line| "#{file} => invalid HAML syntax\n#{line}" if line.gsub(COLOR_REGEXP, '') =~ HAML_INVALID_REGEXP}.compact
143
+ end
144
+ end
145
+ end
146
+
104
147
  def check_best_practices
105
- each_changed_file([:rb, :erb]) do |file|
106
- puts "bundle exec rails_best_practices --spec --test #{file}"
107
- Open3.popen3("bundle exec rails_best_practices --spec --test #{file}") do |stdin, stdout, stderr|
148
+ each_changed_file([:rb, :erb, :haml]) do |file|
149
+ Open3.popen3("rails_best_practices --spec --test #{file}") do |stdin, stdout, stderr|
108
150
  @result.warn(stdout.read.split("\n").map do |line|
109
151
  if line =~ /#{file}/
110
152
  line.gsub(COLOR_REGEXP, '').strip
@@ -141,5 +183,9 @@ module GitHooksHelper
141
183
  puts(text.red)
142
184
  end
143
185
 
186
+ def debug(msg)
187
+ puts msg if @debug
188
+ end
189
+
144
190
  end
145
191
  end
@@ -0,0 +1,8 @@
1
+ module GitHooksHelper
2
+ class Ruby
3
+ def self.check_syntax(file)
4
+ @compiler_ruby = `which ruby`.strip
5
+ "#{@compiler_ruby} -wc #{file}"
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module GitHooksHelper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-hooks-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,32 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-21 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rails-erb-check
16
- requirement: &19072720 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *19072720
25
- - !ruby/object:Gem::Dependency
26
- name: rails_best_practices
27
- requirement: &19071260 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *19071260
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
+ dependencies: []
36
14
  description: Gem for creating simple git hooks in ruby.
37
- email: []
15
+ email:
16
+ - no@email.com
38
17
  executables: []
39
18
  extensions: []
40
19
  extra_rdoc_files: []
@@ -44,15 +23,16 @@ files:
44
23
  - Gemfile.lock
45
24
  - HISTORY
46
25
  - LICENSE
47
- - README
48
26
  - README.md
49
27
  - Rakefile
28
+ - TODO
50
29
  - git-hooks-helper.gemspec
51
30
  - lib/git-hooks-helper.rb
52
31
  - lib/git-hooks-helper/extensions/string.rb
53
32
  - lib/git-hooks-helper/git.rb
54
33
  - lib/git-hooks-helper/hook.rb
55
34
  - lib/git-hooks-helper/result.rb
35
+ - lib/git-hooks-helper/ruby.rb
56
36
  - lib/git-hooks-helper/version.rb
57
37
  - spec/git_files/bad_syntax.rb
58
38
  - spec/git_files/good_syntax.rb
@@ -62,7 +42,7 @@ files:
62
42
  - spec/git_files/syntax_error.html.erb
63
43
  - spec/git_hooks_helper_spec.rb
64
44
  - spec/spec_helper.rb
65
- homepage: ''
45
+ homepage: https://github.com/BuGo/git-hooks-helper
66
46
  licenses: []
67
47
  post_install_message:
68
48
  rdoc_options: []
@@ -82,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
62
  version: '0'
83
63
  requirements: []
84
64
  rubyforge_project: git-hooks-helper
85
- rubygems_version: 1.8.10
65
+ rubygems_version: 1.8.17
86
66
  signing_key:
87
67
  specification_version: 3
88
68
  summary: Small gem to help write simple git hooks
data/README DELETED
@@ -1,50 +0,0 @@
1
- Instalation
2
- -----------
3
- gem install git-hooks-helper
4
-
5
- File clasification
6
- ------------------
7
-
8
- Most commands use file classes internally or accept type class as a param.
9
- File type classes and associated file extensions:
10
- 1. :rb - .rb .rake .task .prawn
11
- 2. :js - .js
12
- 3. :erb - .erb
13
-
14
- Usage
15
- -----
16
- Create your hit hook in .git/hooks directory and make it executable.
17
-
18
- My example pre-commit hook that i use myself.
19
- To create such a hook type in console:
20
-
21
- cd your/project/
22
- touch .git/hooks/pre-commit
23
- chmod +x .git/hooks/pre-commit
24
- vim .git/hooks/pre-commit
25
-
26
- and paste following code:
27
-
28
-
29
- ```ruby
30
- #!/usr/bin/env ruby
31
-
32
- require "git-hooks-helper"
33
-
34
- GitHooksHelper.results do
35
- # fail/pass options
36
- # stop_on_warnings # makes git commit fail if any warnings are found
37
- # never_stop # hooks never fails commits
38
- # list_files # shows list of all changed files
39
-
40
- # schecks
41
- check_ruby_syntax # errors when ruby syntax has errors
42
- check_erb # errors when ERB syntax has errors
43
- check_best_practices # warnings when ruby best practices are violated
44
- warning_on "WTF?", "binding.pry", "<<<<<<<" # warnings when any of these texts are present in any commited files
45
- warning_on "console.log", "debugger", {:in => [:js]} # warning when any of these texts are present in JS files
46
-
47
- # messages
48
- info "Run rspec tests and have a nice day."
49
- end
50
- ```