tdx 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ae0f4d28218fa32505b5ba67bff2d0e629a701
4
- data.tar.gz: 93a5f11f411f7e4a828de06dd08d55dd0e7e5779
3
+ metadata.gz: 60591d8400307a666c5abbbb58e96e6528e73eaa
4
+ data.tar.gz: 8c104eacfad5476280f0f226f94b5e2d103bd6af
5
5
  SHA512:
6
- metadata.gz: 93e159d2fdf9750812d8919257feaada185a1bb61fdeb47c05bcec96312c257821bb5dfcf298dddfa1a2ab0afb909abddfdf4cd0166d8f6d0601dd45974a9348
7
- data.tar.gz: 3ccca087d77a9356d00ba755c880feaeb2444ff88b5887ed22f7ef9359bcdd944c1f8e705a3f508def8ee966d7c1cf746b7acd18f2ef73b08dadb2d3930c4e78
6
+ metadata.gz: 6fdfaf587263cbac81f441a558db61f92f8e5fdd37eeb6cd253c3a1a1af34b5c14794a142f7297563fafc00ba43a417b770188d011e0aa89a02bb93ec9782b61
7
+ data.tar.gz: 78a8910b954fd31905978f0b6565048a4cda084ea6bc71b891624956010db985ccfed1d6aea9b2988ffcc6c9835c42cfa2f2d11da3abb818c087a2681fc4dc29
data/lib/tdx/base.rb CHANGED
@@ -25,6 +25,7 @@ require 'yaml'
25
25
  require 'octokit'
26
26
  require 'fileutils'
27
27
  require 'English'
28
+ require 'tdx/exec'
28
29
 
29
30
  # TDX main module.
30
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -40,20 +41,18 @@ module TDX
40
41
 
41
42
  def svg
42
43
  dat = Tempfile.new('tdx')
43
- version = `git --version`.split(/ /)[2]
44
+ version = Exec.new('git --version').stdout.split(/ /)[2]
44
45
  raise "git version #{version} is too old, upgrade it to 2.0+" unless
45
46
  Gem::Version.new(version) >= Gem::Version.new('2.0')
46
47
  path = checkout
47
- commits =
48
- `cd "#{path}" && git log '--pretty=format:%H %cI' --reverse`
49
- .split(/\n/)
50
- .map { |c| c.split(' ') }
48
+
49
+ commits = Exec.new('git log "--pretty=format:%H %cI" --reverse', path)
50
+ .stdout.split(/\n/).map { |c| c.split(' ') }
51
51
  issues = issues(commits)
52
- puts "Date\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA"
52
+ puts "Date\t\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA"
53
53
  commits.each do |sha, date|
54
- `cd "#{path}" && git checkout --quiet #{sha}`
55
- raise 'Failed to checkout' unless $CHILD_STATUS.exitstatus == 0
56
- line = "#{date[0, 10]}\t#{tests(path)}\t#{hoc(path)}\t#{files(path)}\t\
54
+ Exec.new("git checkout --quiet #{sha}", path).stdout
55
+ line = "#{date[0, 16]}\t#{tests(path)}\t#{hoc(path)}\t#{files(path)}\t\
57
56
  #{loc(path)}\t#{issues[sha]}\t#{sha[0, 7]}"
58
57
  dat << "#{line}\n"
59
58
  puts line
@@ -81,8 +80,7 @@ module TDX
81
80
  ', "" using 1:6 with boxes title "Issues" linecolor rgb "orange"'
82
81
  ].join(' ')
83
82
  ]
84
- `gnuplot -e '#{gpi.join('; ')}'`
85
- raise 'Failed to run Gnuplot' unless $CHILD_STATUS.exitstatus == 0
83
+ Exec.new("gnuplot -e '#{gpi.join('; ')}'").stdout
86
84
  FileUtils.rm_rf(path)
87
85
  File.delete(dat)
88
86
  xml = File.read(svg)
@@ -94,8 +92,7 @@ module TDX
94
92
 
95
93
  def checkout
96
94
  dir = Dir.mktmpdir
97
- `cd #{dir} && git clone --quiet #{@uri} .`
98
- raise 'Failed to clone repository' unless $CHILD_STATUS.exitstatus == 0
95
+ Exec.new("git clone --quiet #{@uri} .", dir).stdout
99
96
  size = Dir.glob(File.join(dir, '**/*'))
100
97
  .map(&:size)
101
98
  .inject(0) { |a, e| a + e }
@@ -108,9 +105,7 @@ module TDX
108
105
  end
109
106
 
110
107
  def loc(path)
111
- cloc = `cd "#{path}" && cloc . --yaml --quiet`
112
- raise 'Failed to run cloc' unless $CHILD_STATUS.exitstatus == 0
113
- yaml = YAML.load(cloc)
108
+ yaml = YAML.load(Exec.new('cloc . --yaml --quiet', path).stdout)
114
109
  if yaml
115
110
  yaml['SUM']['code']
116
111
  else
@@ -119,15 +114,11 @@ module TDX
119
114
  end
120
115
 
121
116
  def hoc(path)
122
- hoc = `cd "#{path}" && hoc`
123
- raise 'Failed to run hoc' unless $CHILD_STATUS.exitstatus == 0
124
- hoc.strip
117
+ Exec.new('hoc', path).stdout.strip
125
118
  end
126
119
 
127
120
  def tests(path)
128
- hoc = `cd "#{path}" && hoc`
129
- raise 'Failed to run hoc' unless $CHILD_STATUS.exitstatus == 0
130
- hoc.strip
121
+ Exec.new('hoc', path).stdout.strip
131
122
  end
132
123
 
133
124
  def issues(commits)
@@ -142,7 +133,9 @@ module TDX
142
133
  else
143
134
  @uri.gsub(%r{^https://github\.com/|\.git$}, '')
144
135
  end
145
- client.list_issues(repo, state: :all).map(&:created_at)
136
+ list = client.list_issues(repo, state: :all).map(&:created_at)
137
+ puts "Loaded #{list.length} issues from GitHub repo '#{repo}'"
138
+ list
146
139
  else
147
140
  []
148
141
  end
data/lib/tdx/exec.rb ADDED
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'date'
24
+ require 'yaml'
25
+ require 'octokit'
26
+ require 'fileutils'
27
+ require 'English'
28
+
29
+ # TDX main module.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2017 Yegor Bugayenko
32
+ # License:: MIT
33
+ module TDX
34
+ # Command line executor
35
+ class Exec
36
+ def initialize(cmd, dir = '.')
37
+ @cmd = cmd
38
+ @dir = dir
39
+ end
40
+
41
+ def stdout
42
+ out = `cd #{@dir} && #{@cmd} 2>/dev/null`
43
+ raise 'Previous command failed' unless $CHILD_STATUS.exitstatus == 0
44
+ out
45
+ end
46
+ end
47
+ end
data/lib/tdx/version.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2017 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module TDX
28
- VERSION = '0.2.1'.freeze
28
+ VERSION = '0.2.2'.freeze
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -179,6 +179,7 @@ files:
179
179
  - features/support/env.rb
180
180
  - lib/tdx.rb
181
181
  - lib/tdx/base.rb
182
+ - lib/tdx/exec.rb
182
183
  - lib/tdx/version.rb
183
184
  - tdx.gemspec
184
185
  - test/test__helper.rb