hoc 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rultor.yml CHANGED
@@ -4,6 +4,7 @@ assets:
4
4
 
5
5
  install: |
6
6
  sudo gem install pdd
7
+ sudo apt-get install -y subversion diffstat
7
8
 
8
9
  release:
9
10
  script: |
data/.travis.yml CHANGED
@@ -4,8 +4,10 @@ branches:
4
4
  only:
5
5
  - master
6
6
  install:
7
- - sudo apt-get update
8
- - travis_retry sudo apt-get install -y --fix-missing libmagic1 libmagic-dev
7
+ - travis_retry sudo apt-get update
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
11
  - travis_retry bundle install
10
12
  script:
11
13
  - rake
data/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
  Install it first:
11
11
 
12
12
  ```bash
13
- gem install hoc
13
+ $ gem install hoc
14
14
  ```
15
15
 
16
16
  Run it locally and read its output:
17
17
 
18
18
  ```bash
19
- hoc --help
19
+ $ hoc --help
20
20
  ```
data/bin/hoc CHANGED
@@ -30,7 +30,8 @@ require 'hoc/version'
30
30
 
31
31
  opts = Slop.parse(ARGV, strict: true, help: true) do
32
32
  banner "Usage (#{HOC::VERSION}): hoc [options]"
33
- on 'f', 'format', 'Output format (text|xml|json|int)', default: 'int'
33
+ on 'f', 'format', 'Output format (text|xml|json|int)',
34
+ default: 'int', argument: :required
34
35
  end
35
36
 
36
37
  if opts.help?
data/lib/hoc.rb CHANGED
@@ -22,6 +22,7 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  require 'hoc/git'
25
+ require 'hoc/svn'
25
26
 
26
27
  # HOC main module.
27
28
  # Author:: Yegor Bugayenko (yegor@teamed.io)
@@ -36,15 +37,20 @@ module HOC
36
37
  def initialize(dir, format)
37
38
  @dir = dir
38
39
  @format = format
40
+ fail "only int format is supported (#{@format})" unless @format == 'int'
39
41
  end
40
42
 
41
43
  # Generate report.
42
44
  def report
45
+ repo = nil
43
46
  if File.exist?(File.join(@dir, '.git'))
44
- Git.new(@dir).hits.map { |h| h.total }.inject(:+)
47
+ repo = Git.new(@dir)
48
+ elsif File.exist?(File.join(@dir, '.svn'))
49
+ repo = Svn.new(@dir)
45
50
  else
46
51
  fail 'only Git repositories supported now'
47
52
  end
53
+ repo.hits.map { |h| h.total }.inject(:+)
48
54
  end
49
55
  end
50
56
  end
data/lib/hoc/svn.rb ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2014 Teamed.io
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'date'
25
+ require 'hoc/hits'
26
+
27
+ module HOC
28
+ # Subversion source code base.
29
+ class Svn
30
+ def initialize(dir)
31
+ @dir = dir
32
+ end
33
+
34
+ def hits
35
+ version = `svn --version --quiet`
36
+ fail "svn version #{version} is too old" unless
37
+ Gem::Version.new(version) >= Gem::Version.new('1.7')
38
+ fail 'diffstat is not installed' if `diffstat -V`.index('version').nil?
39
+ log = `cd '#{@dir}'; svn log --diff | diffstat`
40
+ [
41
+ Hits.new(
42
+ Time.now,
43
+ log.split(/\n/).last.split(/[^\d]/)
44
+ .map { |s| s.to_i }.select { |x| x > 0 }
45
+ .drop(1).inject(:+)
46
+ )
47
+ ]
48
+ end
49
+ end
50
+ end
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.2'
29
+ VERSION = '0.3'
30
30
  end
data/test/test_git.rb CHANGED
@@ -34,7 +34,6 @@ class TestGit < Minitest::Test
34
34
  Dir.mktmpdir 'test' do |dir|
35
35
  system("
36
36
  set -e
37
- set -x
38
37
  cd '#{dir}'
39
38
  git init .
40
39
  git config user.email test@teamed.io
data/test/test_hoc.rb CHANGED
@@ -31,11 +31,10 @@ require 'slop'
31
31
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
32
32
  # License:: MIT
33
33
  class TestHOC < Minitest::Test
34
- def test_basic
34
+ def test_basic_git
35
35
  Dir.mktmpdir 'test' do |dir|
36
36
  system("
37
37
  set -e
38
- set -x
39
38
  cd '#{dir}'
40
39
  git init .
41
40
  git config user.email test@teamed.io
@@ -44,14 +43,35 @@ class TestHOC < Minitest::Test
44
43
  git add test.txt
45
44
  git commit -am test
46
45
  ")
47
- assert HOC::Base.new(dir, 'total').report > 0
46
+ assert HOC::Base.new(dir, 'int').report > 0
47
+ end
48
+ end
49
+
50
+ def test_basic_svn
51
+ Dir.mktmpdir 'test' do |dir|
52
+ system("
53
+ set -e
54
+ cd '#{dir}'
55
+ svnadmin create base
56
+ svn co file://#{dir}/base repo
57
+ cd repo
58
+ echo 'Hello, world!' > test.txt
59
+ svn add test.txt
60
+ svn ci -m 'first commit'
61
+ echo 'Bye!' > test.txt
62
+ svn ci -m 'second commit'
63
+ svn rm test.txt
64
+ svn ci -m 'third commit'
65
+ svn up
66
+ ")
67
+ assert HOC::Base.new(File.join(dir, 'repo'), 'int').report > 0
48
68
  end
49
69
  end
50
70
 
51
71
  def test_fails_if_not_repo
52
72
  Dir.mktmpdir 'test' do |dir|
53
73
  assert_raises RuntimeError do
54
- HOC::Base.new(dir, 'total').report
74
+ HOC::Base.new(dir, 'int').report
55
75
  end
56
76
  end
57
77
  end
data/test/test_svn.rb ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2014 Teamed.io
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require 'hoc/svn'
26
+ require 'tmpdir'
27
+
28
+ # Svn test.
29
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
30
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestSvn < Minitest::Test
33
+ def test_parsing
34
+ Dir.mktmpdir 'test' do |dir|
35
+ system("
36
+ set -e
37
+ cd '#{dir}'
38
+ svnadmin create base
39
+ svn co file://#{dir}/base repo
40
+ cd repo
41
+ echo 'Hello, world!' > test.txt
42
+ svn add test.txt
43
+ svn ci -m 'first commit'
44
+ echo 'Bye!' > test.txt
45
+ svn ci -m 'second commit'
46
+ svn rm test.txt
47
+ svn ci -m 'third commit'
48
+ svn up
49
+ ")
50
+ hits = HOC::Svn.new(File.join(dir, 'repo')).hits
51
+ assert_equal 1, hits.size
52
+ assert_equal 4, hits[0].total
53
+ end
54
+ end
55
+ 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.2'
4
+ version: '0.3'
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-12 00:00:00.000000000 Z
12
+ date: 2014-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
@@ -184,10 +184,12 @@ files:
184
184
  - lib/hoc.rb
185
185
  - lib/hoc/git.rb
186
186
  - lib/hoc/hits.rb
187
+ - lib/hoc/svn.rb
187
188
  - lib/hoc/version.rb
188
189
  - test/test_git.rb
189
190
  - test/test_helper.rb
190
191
  - test/test_hoc.rb
192
+ - test/test_svn.rb
191
193
  homepage: http://github.com/teamed/hoc
192
194
  licenses:
193
195
  - MIT
@@ -222,3 +224,4 @@ test_files:
222
224
  - test/test_git.rb
223
225
  - test/test_helper.rb
224
226
  - test/test_hoc.rb
227
+ - test/test_svn.rb