hoc 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.rultor.yml CHANGED
@@ -5,6 +5,11 @@ assets:
5
5
  install: |
6
6
  sudo gem install pdd
7
7
  sudo apt-get install -y subversion diffstat
8
+ sudo apt-get install -y software-properties-common
9
+ sudo add-apt-repository -y ppa:git-core/ppa
10
+ sudo apt-get update
11
+ sudo apt-get remove -y git
12
+ sudo apt-get install -y git
8
13
 
9
14
  release:
10
15
  script: |
data/.travis.yml CHANGED
@@ -6,8 +6,11 @@ branches:
6
6
  install:
7
7
  - travis_retry sudo apt-get update
8
8
  - travis_retry sudo apt-get install -y diffstat
9
- - travis_retry sudo apt-get install -y subversion
10
- - travis_retry sudo apt-get upgrade subversion
9
+ - travis_retry sudo apt-get remove -y subversion git
10
+ - travis_retry sudo add-apt-repository "deb http://ppa.launchpad.net/svn/ppa/ubuntu precise main"
11
+ - travis_retry sudo add-apt-repository -y ppa:git-core/ppa
12
+ - travis_retry sudo apt-get update
13
+ - travis_retry sudo apt-get install -y subversion git
11
14
  - travis_retry bundle install
12
15
  script:
13
16
  - rake
data/README.md CHANGED
@@ -7,6 +7,11 @@
7
7
  [![Code Climate](http://img.shields.io/codeclimate/github/teamed/hoc.svg)](https://codeclimate.com/github/teamed/hoc)
8
8
  [![Coverage Status](https://img.shields.io/coveralls/teamed/hoc.svg)](https://coveralls.io/r/teamed/hoc)
9
9
 
10
+ It is a command line tool to calculate Hits-of-Code metric
11
+ in a source code repository (at the moment we support Git 2+ and Subversion 1.7+).
12
+ You can read more about Hits-of-Code metric in this blog post:
13
+ [Hits-of-Code Instead of SLoC](http://www.yegor256.com/2014/11/14/hits-of-code.html).
14
+
10
15
  Install it first:
11
16
 
12
17
  ```bash
@@ -18,3 +23,5 @@ Run it locally and read its output:
18
23
  ```bash
19
24
  $ hoc --help
20
25
  ```
26
+
27
+
data/lib/hoc/git.rb CHANGED
@@ -32,16 +32,18 @@ module HOC
32
32
  end
33
33
 
34
34
  def hits
35
- log = `git '--git-dir=#{@dir}/.git' log --pretty=format:%ci --numstat`
36
- log.split(/\n\n/).map do |c|
37
- lines = c.split(/\n/)
35
+ version = `git --version`.split(/ /)[2]
36
+ fail "git version #{version} is too old, upgrade it to 2.0+" unless
37
+ Gem::Version.new(version) >= Gem::Version.new('2.0')
38
+ log = `git '--git-dir=#{@dir}/.git' log --pretty=tformat: --numstat`
39
+ [
38
40
  Hits.new(
39
- Date.parse(lines[0]),
40
- lines.drop(1).map do |f|
41
- f.split(/\t/).take(2).map { |s| s.to_i }.inject(:+)
41
+ Time.now,
42
+ log.split(/\n/).map do |t|
43
+ t.split(/\t/).take(2).map { |s| s.to_i }.inject(:+)
42
44
  end.inject(:+)
43
45
  )
44
- end
46
+ ]
45
47
  end
46
48
  end
47
49
  end
data/lib/hoc/svn.rb CHANGED
@@ -33,9 +33,10 @@ module HOC
33
33
 
34
34
  def hits
35
35
  version = `svn --version --quiet`
36
- fail "svn version #{version} is too old" unless
36
+ fail "svn version #{version} is too old, upgrade it to 1.7+" unless
37
37
  Gem::Version.new(version) >= Gem::Version.new('1.7')
38
- fail 'diffstat is not installed' if `diffstat -V`.index('version').nil?
38
+ fail 'diffstat is not installed' if
39
+ `diffstat -V`.index('version').nil?
39
40
  log = `cd '#{@dir}'; svn log --diff | diffstat`
40
41
  [
41
42
  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.3'
29
+ VERSION = '0.4'
30
30
  end
data/test/test_git.rb CHANGED
@@ -32,7 +32,7 @@ require 'tmpdir'
32
32
  class TestGit < Minitest::Test
33
33
  def test_parsing
34
34
  Dir.mktmpdir 'test' do |dir|
35
- system("
35
+ fail unless system("
36
36
  set -e
37
37
  cd '#{dir}'
38
38
  git init .
@@ -47,10 +47,8 @@ class TestGit < Minitest::Test
47
47
  git commit -am 'delete line'
48
48
  ")
49
49
  hits = HOC::Git.new(dir).hits
50
- assert_equal 3, hits.size
51
- assert_equal 1, hits[0].total
52
- assert_equal 2, hits[1].total
53
- assert_equal 1, hits[2].total
50
+ assert_equal 1, hits.size
51
+ assert_equal 4, hits[0].total
54
52
  end
55
53
  end
56
54
  end
data/test/test_hoc.rb CHANGED
@@ -33,7 +33,7 @@ require 'slop'
33
33
  class TestHOC < Minitest::Test
34
34
  def test_basic_git
35
35
  Dir.mktmpdir 'test' do |dir|
36
- system("
36
+ fail unless system("
37
37
  set -e
38
38
  cd '#{dir}'
39
39
  git init .
@@ -49,7 +49,7 @@ class TestHOC < Minitest::Test
49
49
 
50
50
  def test_basic_svn
51
51
  Dir.mktmpdir 'test' do |dir|
52
- system("
52
+ fail unless system("
53
53
  set -e
54
54
  cd '#{dir}'
55
55
  svnadmin create base
data/test/test_svn.rb CHANGED
@@ -32,7 +32,7 @@ require 'tmpdir'
32
32
  class TestSvn < Minitest::Test
33
33
  def test_parsing
34
34
  Dir.mktmpdir 'test' do |dir|
35
- system("
35
+ fail unless system("
36
36
  set -e
37
37
  cd '#{dir}'
38
38
  svnadmin create base
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.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: