hoc 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,12 +11,23 @@ Feature: Command Line Processing
11
11
  Given I run bash:
12
12
  """
13
13
  set -e
14
- set -x
15
14
  git init .
15
+ git config user.email test@teamed.io
16
+ git config user.name test
16
17
  echo 'hello, world!' > test.txt
17
18
  git add test.txt
18
- git commit -m test
19
+ git commit -am test
19
20
  """
20
21
  When I run bin/hoc with "-f int"
21
22
  Then Exit code is zero
22
23
  And Stdout contains "1"
24
+
25
+ Scenario: Real git repo
26
+ Given I run bash:
27
+ """
28
+ set -e
29
+ rm -rf *
30
+ git clone https://github.com/teamed/hoc.git .
31
+ """
32
+ When I run bin/hoc with "-f int"
33
+ Then Exit code is zero
data/lib/hoc.rb CHANGED
@@ -40,7 +40,11 @@ module HOC
40
40
 
41
41
  # Generate report.
42
42
  def report
43
- Git.new(@dir).hits.map { |h| h.total }.inject(:+)
43
+ if File.exist?(File.join(@dir, '.git'))
44
+ Git.new(@dir).hits.map { |h| h.total }.inject(:+)
45
+ else
46
+ fail 'only Git repositories supported now'
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -21,6 +21,7 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
23
 
24
+ require 'date'
24
25
  require 'hoc/hits'
25
26
 
26
27
  module HOC
@@ -31,9 +32,16 @@ module HOC
31
32
  end
32
33
 
33
34
  def hits
34
- [
35
- Hits.new(Time.new(0), Time.new(0), 1)
36
- ]
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/)
38
+ 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(:+)
42
+ end.inject(:+)
43
+ )
44
+ end
37
45
  end
38
46
  end
39
47
  end
@@ -24,11 +24,10 @@
24
24
  module HOC
25
25
  # Set of hits.
26
26
  class Hits
27
- def initialize(first, last, total)
28
- @first = first
29
- @last = last
27
+ def initialize(date, total)
28
+ @date = date
30
29
  @total = total
31
30
  end
32
- attr_reader :first, :last, :total
31
+ attr_reader :date, :total
33
32
  end
34
33
  end
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module HOC
29
- VERSION = '0.1'
29
+ VERSION = '0.2'
30
30
  end
@@ -37,12 +37,21 @@ class TestGit < Minitest::Test
37
37
  set -x
38
38
  cd '#{dir}'
39
39
  git init .
40
+ git config user.email test@teamed.io
41
+ git config user.name test
40
42
  echo 'hello, world!' > test.txt
41
43
  git add test.txt
42
- git commit -m test
44
+ git commit -am 'add line'
45
+ echo 'good bye, world!' > test.txt
46
+ git commit -am 'modify line'
47
+ rm test.txt
48
+ git commit -am 'delete line'
43
49
  ")
44
50
  hits = HOC::Git.new(dir).hits
45
- assert_equal 1, hits.size
51
+ assert_equal 3, hits.size
52
+ assert_equal 1, hits[0].total
53
+ assert_equal 2, hits[1].total
54
+ assert_equal 1, hits[2].total
46
55
  end
47
56
  end
48
57
  end
@@ -38,11 +38,21 @@ class TestHOC < Minitest::Test
38
38
  set -x
39
39
  cd '#{dir}'
40
40
  git init .
41
+ git config user.email test@teamed.io
42
+ git config user.name test
41
43
  echo 'hello, world!' > test.txt
42
44
  git add test.txt
43
- git commit -m test
45
+ git commit -am test
44
46
  ")
45
47
  assert HOC::Base.new(dir, 'total').report > 0
46
48
  end
47
49
  end
50
+
51
+ def test_fails_if_not_repo
52
+ Dir.mktmpdir 'test' do |dir|
53
+ assert_raises RuntimeError do
54
+ HOC::Base.new(dir, 'total').report
55
+ end
56
+ end
57
+ end
48
58
  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.1'
4
+ version: '0.2'
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: 2014-11-11 00:00:00.000000000 Z
12
+ date: 2014-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop