codeqa 0.4.2 → 0.5.0

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: c958a6611a0a955d10a405401ee880c160110143
4
- data.tar.gz: 16f4f0891d4d30e803949670068762f5771a8dc6
3
+ metadata.gz: e9b19bbc570eb76e3e5a6254ead39215713a363d
4
+ data.tar.gz: 061d9968aaacf02778dda744ac40a3003b59bb86
5
5
  SHA512:
6
- metadata.gz: 0089efc75482dca33f4da9fd752be74647d1e1b19f5a299a70e2cd31b48dfe317bb82fb0fe95453ac14af77aa94928184f9896dd16c147d6b87d4bc8763f5b26
7
- data.tar.gz: adc7c3549c7d1dbd44d210924388a3923a819256eaacb9c91c6564e5c198b801efdbe55737386927a173ff4287cf5177637a256cf2d0e6d0ca2465628e5959e4
6
+ metadata.gz: 465e4bba1c98ac836288de4b6e5d88dacfb972268a0088cc959e365d3bf108c7b464ca1c36831becbf54d1db53f3c2a511c095b38b50395d161c97c599d6d619
7
+ data.tar.gz: 2f0daf5c332a5fe9b18b9bbb31eb735960a56f63898ff8ab0e16f3d0e386e4adc20ad26c85d7731b02a86f34d653fbefa449bbde991cec35ec18ce7ae047d14a
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.5.0
2
+ * INCOMPATIBLE CHANGE: new config layout (now config has to be in .codeqa/config.rb)
3
+ * multiple hooks in any language is allowed (create scripts in .codeqa/hooks)
1
4
  0.2.1
2
5
  * fixing missing ERB error
3
6
  0.2.0
data/README.md CHANGED
@@ -33,9 +33,9 @@ Since Version 0.3 codeqa uses ruby for configuration, therefore the config file
33
33
  is now named `.codeqa.rb`. The loading of configuration files is still the same,
34
34
  meaning we have to following load order:
35
35
 
36
- 1. Initialize with default settings (see `config/default..rb`)
37
- 2. load `.codeqa.rb` from your home directory and merge it with the defaults.
38
- 3. load `.codeqa.rb` placed in the project root, which is determined by finding
36
+ 1. Initialize with default settings (see `config/default.rb`)
37
+ 2. load `.codeqa/config.rb` from your home directory and merge it with the defaults.
38
+ 3. load `.codeqa/config.rb` placed in the project root, which is determined by finding
39
39
  the closest `.git` folder.
40
40
 
41
41
  Both the config in your home directory and the project config file are optional
@@ -90,6 +90,10 @@ end
90
90
  - CheckYard (checks YARD for warnings)
91
91
  - CheckRubySyntax (runs file though `ruby -c`, use RubocopLint if possible)
92
92
 
93
+ ## Hooks
94
+ Since version 0.5 it's possible to run any scripts which are placed at .codeqa/hooks . If they exit with code <> 0
95
+ the commit is not allowed. The scripts have to be executable.
96
+
93
97
  ## Contributing
94
98
 
95
99
  1. Fork it
data/bin/codeqa CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << File.join(File.dirname(__FILE__), '../lib') if ENV['CODEQA_DEV']
3
+ $: << File.join(File.dirname(__FILE__), '../lib') unless $PROGRAM_NAME == 'codeqa'
4
4
  require 'rubygems'
5
5
  require 'codeqa'
6
6
 
@@ -8,25 +8,8 @@ module Codeqa
8
8
  end
9
9
 
10
10
  def install(root='.')
11
- require 'fileutils'
12
- git_root = Pathname.new "#{root}/.git"
13
- if File.exist?(git_root)
14
- pre_commit_path = git_root.join 'hooks', 'pre-commit'
15
- if File.exist?(pre_commit_path)
16
- # $stdout.puts 'moving away the old pre-commit hook -> pre-commit.bkp'
17
- FileUtils.mv(pre_commit_path,
18
- git_root.join('hooks', 'pre-commit.bkp'),
19
- :force => true)
20
- end
21
- pre_commit_template_path = Codeqa.root.join('lib', 'templates', 'pre-commit')
22
- # $stdout.puts 'placing new pre-commit hook'
23
- FileUtils.cp(pre_commit_template_path, pre_commit_path)
24
- FileUtils.chmod('+x', pre_commit_path)
25
- true
26
- else
27
- # $stderr.puts "#{root} is not in a git root"
28
- false
29
- end
11
+ require 'codeqa/installer'
12
+ Codeqa::Installer.call(root)
30
13
  end
31
14
 
32
15
  def check(filename, options={})
@@ -47,7 +47,7 @@ module Codeqa
47
47
 
48
48
  private
49
49
 
50
- DOTFILE = '.codeqa.rb'
50
+ DOTFILE = '.codeqa/config.rb'
51
51
 
52
52
  def home_dir
53
53
  @home_dir ||= Dir.home
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+
3
+ module Codeqa
4
+ class Installer
5
+ def self.call(app_root)
6
+ new(app_root).call
7
+ end
8
+
9
+ def initialize(app_root)
10
+ @app_root=Pathname.new(File.expand_path(app_root))
11
+ end
12
+
13
+ def call
14
+ generate_dot_codeqa
15
+ install_codeqa_git_hook
16
+ end
17
+
18
+ private
19
+ def dot_path(*args)
20
+ app_path('.codeqa').join(*args)
21
+ end
22
+
23
+ def app_path(*args)
24
+ @app_root.join(*args)
25
+ end
26
+
27
+ private
28
+ def template_path(*args)
29
+ Codeqa.root.join('lib', 'templates').join(*args)
30
+ end
31
+
32
+ def install_codeqa_git_hook
33
+ git_root = app_path.join(".git")
34
+ pre_commit_path = git_root.join 'hooks', 'pre-commit'
35
+
36
+ return false unless File.exist?(git_root)
37
+ return false if File.exist?(pre_commit_path)
38
+
39
+ FileUtils.mv(pre_commit_path,
40
+ git_root.join('hooks', 'pre-commit.bkp'),
41
+ :force => true)
42
+ pre_commit_path.make_symlink('../../.codeqa/git_hook.rb') #relative path!
43
+ true
44
+ end
45
+
46
+ def generate_dot_codeqa
47
+ dot_path.mkdir unless dot_path.exist?
48
+ dot_path("hooks").mkdir unless dot_path("hooks").exist?
49
+ FileUtils.cp(template_path('base_hook.rb'), dot_path("hooks","base.rb")) unless dot_path("hooks","base.rb").exist?
50
+ FileUtils.cp(template_path('git_hook.rb'), dot_path("git_hook.rb")) unless dot_path("git_hook.rb").exist?
51
+ dot_path("git_hook.rb").chmod(0775)
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Codeqa
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # running codeqa checks on changes files
4
+
3
5
  def staged_files
4
6
  @staged_files ||= begin
5
7
  files = `git diff --cached --name-only --diff-filter=ACM`.split
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ APP_ROOT=Pathname.new(File.expand_path(File.join(File.dirname(__FILE__),'..','..')))
5
+ HOOKS_PATH=APP_ROOT.join('.codeqa','hooks')
6
+
7
+
8
+ #run each hook if one gives an error then commit will fail
9
+
10
+ HOOKS_PATH.children(false).sort.each do |filename|
11
+ exe=HOOKS_PATH.join(filename)
12
+ ok=system(%{#{exe} APP_ROOT="#{APP_ROOT}"})
13
+ exit 1 unless ok
14
+ end
15
+
16
+ exit 0
@@ -42,11 +42,11 @@ describe Codeqa do
42
42
  end
43
43
 
44
44
  it 'should copy pre-commit hook into project git folder' do
45
- template_location = Codeqa.root.join('lib', 'templates', 'pre-commit')
46
- hook_location = project_dir.join('.git', 'hooks', 'pre-commit')
47
- expect(FileUtils).to receive(:cp).with(template_location, hook_location)
48
- allow(FileUtils).to receive(:chmod)
49
45
  Codeqa.install project_dir.to_s
46
+ expect(project_dir.join('.codeqa')).to be_exist
47
+ expect(project_dir.join('.codeqa','hooks')).to be_exist
48
+ expect(project_dir.join('.codeqa','hooks','base.rb')).to be_exist
49
+ expect(project_dir.join('.codeqa','git_hook.rb')).to be_exist
50
50
  end
51
51
  end
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-18 00:00:00.000000000 Z
12
+ date: 2015-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -108,7 +108,6 @@ files:
108
108
  - ".gitignore"
109
109
  - ".rspec"
110
110
  - ".rubocop.yml"
111
- - ".ruby-version"
112
111
  - ".travis.yml"
113
112
  - ".vimrc"
114
113
  - CHANGELOG
@@ -138,13 +137,15 @@ files:
138
137
  - lib/codeqa/checkers/rubocop_full.rb
139
138
  - lib/codeqa/checkers/rubocop_lint.rb
140
139
  - lib/codeqa/configuration.rb
140
+ - lib/codeqa/installer.rb
141
141
  - lib/codeqa/runner.rb
142
142
  - lib/codeqa/runner_decorator.rb
143
143
  - lib/codeqa/sourcefile.rb
144
144
  - lib/codeqa/utils/check_errors.rb
145
145
  - lib/codeqa/utils/erb_sanitizer.rb
146
146
  - lib/codeqa/version.rb
147
- - lib/templates/pre-commit
147
+ - lib/templates/base_hook.rb
148
+ - lib/templates/git_hook.rb
148
149
  - spec/fixtures/erb_example.html
149
150
  - spec/fixtures/erb_example.html.erb
150
151
  - spec/fixtures/html_error.html.erb
@@ -1 +0,0 @@
1
- ruby-2.1.2