Skip to content

Commit 199fa9b

Browse files
committed
Merge pull request #1 from preisanalytics/master
refactoring installation. hook is now just a link into commitable code
2 parents eed8777 + 4611bd5 commit 199fa9b

32 files changed

+180
-61
lines changed
File renamed without changes.

.codeqa/git_hook.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
# run each hook if one gives an error then commit will fail
8+
9+
HOOKS_PATH.children(false).sort.each do |filename|
10+
exe = HOOKS_PATH.join(filename)
11+
ok = system(%(#{exe} APP_ROOT="#{APP_ROOT}"))
12+
exit 1 unless ok
13+
end
14+
15+
exit 0

lib/templates/pre-commit renamed to .codeqa/hooks/base.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
# running codeqa checks on changes files
4+
35
def staged_files
46
@staged_files ||= begin
57
files = `git diff --cached --name-only --diff-filter=ACM`.split
@@ -30,9 +32,9 @@ def binary?(file)
3032
end
3133

3234
files_to_check = staged_files.
33-
map{ |e| Pathname.new(e).realpath.to_s }.
34-
reject{ |e| File.directory?(e) || Codeqa.configuration.excluded?(e) }.
35-
uniq
35+
map{ |e| Pathname.new(e).realpath.to_s }.
36+
reject{ |e| File.directory?(e) || Codeqa.configuration.excluded?(e) }.
37+
uniq
3638

3739
print "Codeqa checking #{files_to_check.count} files"
3840
# fail fast

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ test/version_tmp
1717
tmp
1818
.idea
1919
.rvmrc
20+
/spec/fixtures/.codeqa
21+
/spec/fixtures/isolation/home/project/.codeqa/
2022
!.keep

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: ruby
22
rvm:
3-
- 2.1.2
3+
- 2.2.2
4+
- 2.1.5
45
- 2.0.0
56
- rbx
67
- ruby-head

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
14
0.2.1
25
* fixing missing ERB error
36
0.2.0

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Since Version 0.3 codeqa uses ruby for configuration, therefore the config file
3333
is now named `.codeqa.rb`. The loading of configuration files is still the same,
3434
meaning we have to following load order:
3535

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
3939
the closest `.git` folder.
4040

4141
Both the config in your home directory and the project config file are optional
@@ -90,6 +90,10 @@ end
9090
- CheckYard (checks YARD for warnings)
9191
- CheckRubySyntax (runs file though `ruby -c`, use RubocopLint if possible)
9292

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+
9397
## Contributing
9498

9599
1. Fork it

bin/codeqa

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$: << File.join(File.dirname(__FILE__), '../lib') if ENV['CODEQA_DEV']
3+
$: << File.join(File.dirname(__FILE__), '../lib') unless $PROGRAM_NAME == 'codeqa'
44
require 'rubygems'
55
require 'codeqa'
66

codeqa.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
99
gem.homepage = 'https://github.com/experteer/codeqa'
1010
gem.license = 'MIT'
1111

12-
gem.files = `git ls-files`.split($\)
12+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
1313
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
1414
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
1515
gem.name = 'codeqa'

0 commit comments

Comments
 (0)