hoc 0.4.2 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rultor.yml CHANGED
@@ -3,7 +3,7 @@ assets:
3
3
  s3cfg: "yegor256/home#assets/s3cfg"
4
4
 
5
5
  install: |
6
- sudo gem install pdd
6
+ sudo gem install --no-ri --no-rdoc pdd
7
7
  sudo apt-get install -y subversion diffstat
8
8
  sudo apt-get install -y software-properties-common
9
9
  sudo add-apt-repository -y ppa:git-core/ppa
@@ -17,6 +17,7 @@ release:
17
17
  rake
18
18
  rm -rf *.gem
19
19
  sed -i "s/1\.0\.snapshot/${tag}/g" lib/hoc/version.rb
20
+ git commit -m "${tag}" lib/hoc/version.rb
20
21
  gem build hoc.gemspec
21
22
  chmod 0600 ../rubygems.yml
22
23
  gem push *.gem --config-file ../rubygems.yml
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Gem Version](https://badge.fury.io/rb/hoc.svg)](http://badge.fury.io/rb/hoc)
6
6
  [![Dependency Status](https://gemnasium.com/teamed/hoc.svg)](https://gemnasium.com/teamed/hoc)
7
7
  [![Code Climate](http://img.shields.io/codeclimate/github/teamed/hoc.svg)](https://codeclimate.com/github/teamed/hoc)
8
- [![Coverage Status](https://img.shields.io/coveralls/teamed/hoc.svg)](https://coveralls.io/r/teamed/hoc)
8
+ [![Coverage Status](https://coveralls.io/repos/teamed/hoc/badge.svg)](https://coveralls.io/r/teamed/hoc)
9
9
 
10
10
  It is a command line tool to calculate Hits-of-Code metric
11
11
  in a source code repository (at the moment we support Git 2+ and Subversion 1.7+).
data/bin/hoc CHANGED
@@ -28,10 +28,26 @@ require 'hoc'
28
28
  require 'slop'
29
29
  require 'hoc/version'
30
30
 
31
- opts = Slop.parse(ARGV, strict: true, help: true) do
31
+ args = []
32
+ args.push(*File.read('.hoc').split(/\s+/).map(&:strip)) if File.exist?('.hoc')
33
+ args.push(*ARGV)
34
+
35
+ opts = Slop.parse(args, strict: true, help: true) do
32
36
  banner "Usage (#{HOC::VERSION}): hoc [options]"
33
- on 'f', 'format', 'Output format (text|xml|json|int)',
34
- default: 'int', argument: :required
37
+ on(
38
+ 'f',
39
+ 'format',
40
+ 'Output format (text|xml|json|int)',
41
+ default: 'int',
42
+ argument: :required
43
+ )
44
+ on(
45
+ 'e',
46
+ 'exclude',
47
+ 'Glob pattern to exclude files/dirs, e.g. "vendor/**"',
48
+ as: Array,
49
+ argument: :required
50
+ )
35
51
  end
36
52
 
37
53
  if opts.help?
@@ -42,4 +58,4 @@ end
42
58
  Encoding.default_external = Encoding::UTF_8
43
59
  Encoding.default_internal = Encoding::UTF_8
44
60
 
45
- puts HOC::Base.new(Dir.pwd, opts[:format]).report
61
+ puts HOC::Base.new(Dir.pwd, opts).report
@@ -0,0 +1,21 @@
1
+ Feature: Exclude dirs from Git counting
2
+ As a source code writer I want to be able to
3
+ exclude certain files from counting
4
+
5
+ Scenario: Simple git repo
6
+ Given I run bash:
7
+ """
8
+ set -e
9
+ git init .
10
+ git config user.email test@teamed.io
11
+ git config user.name test
12
+ mkdir x
13
+ echo 'hello, world!' > x/invalid.txt
14
+ echo 'hello, world!' > valid.txt
15
+ git add .
16
+ git commit -am test
17
+ """
18
+ When I run bin/hoc with "-e x/** -e a.txt"
19
+ Then Exit code is zero
20
+ And Stdout contains "1"
21
+
@@ -0,0 +1,15 @@
1
+ Feature: Using .hoc config file
2
+ As a source code writer I want to be able to
3
+ call HOC as a command line tool and configure
4
+ it via .hoc configuration file
5
+
6
+ Scenario: Simple hoc counting
7
+ Given I run bash:
8
+ """
9
+ set -e
10
+ echo '--help' > .hoc
11
+ """
12
+ When I run bin/hoc with "-f int"
13
+ Then Exit code is zero
14
+ And Stdout contains "[options]"
15
+
data/lib/hoc/git.rb CHANGED
@@ -27,8 +27,9 @@ require 'hoc/hits'
27
27
  module HOC
28
28
  # Git source code base.
29
29
  class Git
30
- def initialize(dir)
30
+ def initialize(dir, exclude)
31
31
  @dir = dir
32
+ @exclude = exclude
32
33
  end
33
34
 
34
35
  def hits
@@ -41,7 +42,9 @@ module HOC
41
42
  'log', '--pretty=tformat:', '--numstat',
42
43
  '--ignore-space-change', '--ignore-all-space',
43
44
  '--ignore-submodules', '--no-color',
44
- '--find-copies-harder', '-M', '--diff-filter=ACDM'
45
+ '--find-copies-harder', '-M', '--diff-filter=ACDM',
46
+ '--', '.',
47
+ @exclude.map { |e| "':(exclude,glob)#{e}'" }.join(' ')
45
48
  ].join(' ')
46
49
  [
47
50
  Hits.new(
data/lib/hoc/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module HOC
29
- VERSION = '0.4.2'
29
+ VERSION = '0.5'
30
30
  end
data/lib/hoc.rb CHANGED
@@ -33,18 +33,19 @@ module HOC
33
33
  class Base
34
34
  # Ctor.
35
35
  # +dir+:: Directory to read from
36
- # +format+:: Format (xml, json, text)
37
- def initialize(dir, format)
36
+ # +opts+:: Options
37
+ def initialize(dir, opts)
38
38
  @dir = dir
39
- @format = format
40
- fail "only int format is supported (#{@format})" unless @format == 'int'
39
+ fail "only \"int\" format is supported now" unless
40
+ opts[:format].nil? || opts[:format] == 'int'
41
+ @exclude = opts[:exclude].nil? ? [] : opts[:exclude]
41
42
  end
42
43
 
43
44
  # Generate report.
44
45
  def report
45
46
  repo = nil
46
47
  if File.exist?(File.join(@dir, '.git'))
47
- repo = Git.new(@dir)
48
+ repo = Git.new(@dir, @exclude)
48
49
  elsif File.exist?(File.join(@dir, '.svn'))
49
50
  repo = Svn.new(@dir)
50
51
  else
data/test/test_git.rb CHANGED
@@ -46,21 +46,41 @@ class TestGit < Minitest::Test
46
46
  rm test.txt
47
47
  git commit -am 'delete line'
48
48
  ")
49
- hits = HOC::Git.new(dir).hits
49
+ hits = HOC::Git.new(dir, []).hits
50
50
  assert_equal 1, hits.size
51
51
  assert_equal 4, hits[0].total
52
52
  end
53
53
  end
54
54
 
55
55
  def test_parsing_with_empty_git
56
- skip('fails now')
57
56
  Dir.mktmpdir 'test' do |dir|
58
57
  fail unless system("
59
58
  set -e
60
59
  cd '#{dir}'
61
60
  git init .
62
61
  ")
63
- hits = HOC::Git.new(dir).hits
62
+ hits = HOC::Git.new(dir, []).hits
63
+ assert_equal 1, hits.size
64
+ assert_equal 0, hits[0].total
65
+ end
66
+ end
67
+
68
+ def test_ignores_binary_files
69
+ Dir.mktmpdir 'test' do |dir|
70
+ fail unless system("
71
+ set -e
72
+ cd '#{dir}'
73
+ git init .
74
+ git config user.email test@teamed.io
75
+ git config user.name test
76
+ dd if=/dev/random of=test.dat bs=1 count=65536
77
+ git add test.dat
78
+ git commit -am 'binary file'
79
+ dd if=/dev/random of=test.dat bs=1 count=65536
80
+ git add test.dat
81
+ git commit -am 'binary file modified'
82
+ ")
83
+ hits = HOC::Git.new(dir, []).hits
64
84
  assert_equal 1, hits.size
65
85
  assert_equal 0, hits[0].total
66
86
  end
data/test/test_hoc.rb CHANGED
@@ -43,7 +43,7 @@ class TestHOC < Minitest::Test
43
43
  git add test.txt
44
44
  git commit -am test
45
45
  ")
46
- assert HOC::Base.new(dir, 'int').report > 0
46
+ assert HOC::Base.new(dir, exclude: ['a/**']).report > 0
47
47
  end
48
48
  end
49
49
 
@@ -64,14 +64,22 @@ class TestHOC < Minitest::Test
64
64
  svn ci -m 'third commit'
65
65
  svn up
66
66
  ")
67
- assert HOC::Base.new(File.join(dir, 'repo'), 'int').report > 0
67
+ assert HOC::Base.new(File.join(dir, 'repo'), {}).report > 0
68
68
  end
69
69
  end
70
70
 
71
71
  def test_fails_if_not_repo
72
72
  Dir.mktmpdir 'test' do |dir|
73
73
  assert_raises RuntimeError do
74
- HOC::Base.new(dir, 'int').report
74
+ HOC::Base.new(dir, {}).report
75
+ end
76
+ end
77
+ end
78
+
79
+ def test_fails_if_not_int
80
+ Dir.mktmpdir 'test' do |dir|
81
+ assert_raises RuntimeError do
82
+ HOC::Base.new(dir, format: 'text').report
75
83
  end
76
84
  end
77
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-11 00:00:00.000000000 Z
12
+ date: 2015-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
@@ -164,7 +164,6 @@ extra_rdoc_files:
164
164
  - README.md
165
165
  - LICENSE.txt
166
166
  files:
167
- - .coveralls.yml
168
167
  - .gitignore
169
168
  - .rubocop.yml
170
169
  - .rultor.yml
@@ -178,8 +177,10 @@ files:
178
177
  - cucumber.yml
179
178
  - features/cli.feature
180
179
  - features/gem_package.feature
180
+ - features/git_excludes.feature
181
181
  - features/step_definitions/steps.rb
182
182
  - features/support/env.rb
183
+ - features/uses_config.feature
183
184
  - hoc.gemspec
184
185
  - lib/hoc.rb
185
186
  - lib/hoc/git.rb
@@ -219,8 +220,10 @@ summary: Hits Of Code
219
220
  test_files:
220
221
  - features/cli.feature
221
222
  - features/gem_package.feature
223
+ - features/git_excludes.feature
222
224
  - features/step_definitions/steps.rb
223
225
  - features/support/env.rb
226
+ - features/uses_config.feature
224
227
  - test/test__helper.rb
225
228
  - test/test_git.rb
226
229
  - test/test_hoc.rb
data/.coveralls.yml DELETED
@@ -1,2 +0,0 @@
1
- service_name: travis-pro
2
- repo_token: E8h8J4kUBHZNPsh2leUD2UzW02VCGftrU