tdx 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/README.md +1 -2
- data/bin/tdx +1 -1
- data/lib/tdx/base.rb +59 -54
- data/lib/tdx/exec.rb +4 -1
- data/lib/tdx/version.rb +1 -1
- data/tdx.gemspec +0 -1
- data/test/test__helper.rb +2 -0
- data/test/test_tdx.rb +2 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68d11ea43666fcba743422938f2601d134729df8
|
4
|
+
data.tar.gz: 9010264c48eaa44be853ba28429b6791d7fc3025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a83ceae6741bb1dceecb7b25d9b8843360bc24ffd93e9d67e782df9c4667da6f1b995f74018861265de997a2c22b28f8080bf413a8c4311b6129971319ec9a
|
7
|
+
data.tar.gz: aa159cf35de15d1e93d4ef80d7f9fb2d422672463e33113a0b74dc9b43021000a622c0ae02e11dcf8ba584957a655bff7e768df5611771bf9d6d50936f40f1a5
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
data/bin/tdx
CHANGED
@@ -35,7 +35,7 @@ opts = Slop.parse(args, strict: true, help: true) do |o|
|
|
35
35
|
o.array(
|
36
36
|
'-t', '--tests',
|
37
37
|
'Comma-separated list of glob masks with test-related files',
|
38
|
-
delimiter: ','
|
38
|
+
delimiter: ',', default: []
|
39
39
|
)
|
40
40
|
o.string '-d', '--data', 'Path of .dat file for Gnuplot'
|
41
41
|
o.string '--sha', 'The SHA to start from'
|
data/lib/tdx/base.rb
CHANGED
@@ -38,6 +38,11 @@ module TDX
|
|
38
38
|
def initialize(uri, opts)
|
39
39
|
@uri = uri
|
40
40
|
@opts = opts
|
41
|
+
@issues = nil
|
42
|
+
@pure = nil
|
43
|
+
@hoc = nil
|
44
|
+
@logopts = '--ignore-space-change --no-color --find-copies-harder \
|
45
|
+
--ignore-all-space --ignore-submodules -M --diff-filter=ACDM'
|
41
46
|
end
|
42
47
|
|
43
48
|
def svg
|
@@ -46,51 +51,36 @@ module TDX
|
|
46
51
|
Gem::Version.new(version) >= Gem::Version.new('2.0')
|
47
52
|
path = checkout
|
48
53
|
commits = Exec.new(
|
49
|
-
|
54
|
+
"git log '--pretty=format:%H %cI' #{@logopts} " +
|
50
55
|
(@opts[:sha] ? @opts[:sha] : 'HEAD'),
|
51
56
|
path
|
52
57
|
).stdout.split(/\n/).map { |c| c.split(' ') }
|
53
|
-
|
54
|
-
puts "Date\t\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA\tIdx"
|
58
|
+
puts "Date\t\t\tCode\tTests\tIssues\tSHA\tIdx"
|
55
59
|
metrics = commits.each_with_index.map do |c, i|
|
56
|
-
Exec.new("git checkout --quiet #{c[0]}", path).stdout
|
60
|
+
Exec.new("git checkout --quiet --force #{c[0]}", path).stdout
|
61
|
+
pure = pure(path, c[0])
|
57
62
|
m = {
|
58
63
|
date: c[1],
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
loc: loc(path),
|
63
|
-
issues: issues[c[0]],
|
64
|
+
code: pure,
|
65
|
+
tests: hoc(path, c[0]) - pure,
|
66
|
+
issues: issues(commits)[c[0]],
|
64
67
|
sha: c[0]
|
65
68
|
}
|
66
|
-
puts "#{m[:date][0, 16]}\t#{m[:
|
67
|
-
#{m[:
|
69
|
+
puts "#{m[:date][0, 16]}\t#{m[:code]}\t#{m[:tests]}\t\
|
70
|
+
#{m[:issues]}\t#{m[:sha][0, 7]}\t#{i}/#{commits.size}"
|
68
71
|
m
|
69
72
|
end
|
70
|
-
max = { pure: 0, hoc: 0, files: 0, loc: 0, issues: 0 }
|
71
|
-
max = metrics.inject(max) do |m, t|
|
72
|
-
{
|
73
|
-
pure: [m[:pure], t[:pure], 1].max,
|
74
|
-
hoc: [m[:hoc], t[:hoc], 1].max,
|
75
|
-
files: [m[:files], t[:files], 1].max,
|
76
|
-
loc: [m[:loc], t[:loc], 1].max,
|
77
|
-
issues: [m[:issues], t[:issues], 1].max
|
78
|
-
}
|
79
|
-
end
|
80
73
|
dat = if @opts[:data]
|
81
74
|
File.new(@opts[:data], 'w+')
|
82
75
|
else
|
83
76
|
Tempfile.new('tdx')
|
84
77
|
end
|
85
|
-
metrics.each do |m|
|
78
|
+
metrics.select { |m| m[:code] > 0 }.each do |m|
|
86
79
|
dat << [
|
87
80
|
m[:date],
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
100.0 * m[:files] / max[:files],
|
92
|
-
100.0 * m[:loc] / max[:loc],
|
93
|
-
100.0 * m[:issues] / max[:issues],
|
81
|
+
m[:code],
|
82
|
+
m[:tests],
|
83
|
+
m[:issues],
|
94
84
|
m[:sha]
|
95
85
|
].join(' ') + "\n"
|
96
86
|
end
|
@@ -102,17 +92,18 @@ module TDX
|
|
102
92
|
'set termoption font "monospace,10"',
|
103
93
|
'set xdata time',
|
104
94
|
'set timefmt "%Y-%m"',
|
105
|
-
'set ytics format "%.0f
|
95
|
+
'set ytics format "%.0f" textcolor rgb "black"',
|
96
|
+
'set y2tics format "%.0f" textcolor rgb "orange"',
|
106
97
|
'set grid linecolor rgb "gray"',
|
107
98
|
'set xtics format "%b/%y" font "monospace,8" textcolor rgb "black"',
|
108
|
-
'set autoscale',
|
99
|
+
'set autoscale y',
|
100
|
+
'set autoscale y2',
|
109
101
|
'set style fill solid',
|
110
102
|
'set boxwidth 0.75 relative',
|
111
103
|
[
|
112
|
-
"plot \"#{dat.path}\"
|
113
|
-
'
|
114
|
-
', ""
|
115
|
-
', "" using 1:7 with lines title "Issues" linecolor rgb "orange"'
|
104
|
+
"plot \"#{dat.path}\" u 1:2 w l t \"code\" lc rgb \"#81b341\"",
|
105
|
+
', "" u 1:3 w l t "tests" lc rgb "red"',
|
106
|
+
', "" u 1:4 w l t "Issues" lc rgb "orange" axes x1y2'
|
116
107
|
].join(' ')
|
117
108
|
]
|
118
109
|
Exec.new("gnuplot -e '#{gpi.join('; ')}'").stdout
|
@@ -128,39 +119,43 @@ module TDX
|
|
128
119
|
def checkout
|
129
120
|
dir = Dir.mktmpdir
|
130
121
|
Exec.new("git clone --quiet #{@uri} .", dir).stdout
|
131
|
-
size = Dir.glob(File.join(dir, '
|
132
|
-
.map(&:size)
|
133
|
-
.inject(0) { |a, e| a + e }
|
122
|
+
size = Dir.glob(File.join(dir, '**', '*')).map(&:size).inject(:+)
|
134
123
|
puts "Cloned #{@uri} (#{size / 1024}Kb) into temporary directory"
|
135
124
|
dir
|
136
125
|
end
|
137
126
|
|
138
|
-
def
|
139
|
-
|
127
|
+
def pure(path, sha)
|
128
|
+
@pure = hashes(path, @opts[:tests]) if @pure.nil?
|
129
|
+
sum(@pure, sha)
|
140
130
|
end
|
141
131
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
132
|
+
def hoc(path, sha)
|
133
|
+
@hoc = hashes(path, []) if @hoc.nil?
|
134
|
+
sum(@hoc, sha)
|
145
135
|
end
|
146
136
|
|
147
|
-
def
|
148
|
-
exclude = if @opts[:tests]
|
149
|
-
@opts[:tests].map { |e| "--exclude=#{e}" }
|
150
|
-
else
|
151
|
-
[]
|
152
|
-
end
|
137
|
+
def hashes(path, excludes)
|
153
138
|
Exec.new(
|
154
|
-
|
139
|
+
"git log --pretty=tformat:%H --numstat #{@logopts} -- . " +
|
140
|
+
excludes.map { |e| "':(exclude,glob)#{e}'" }.join(' '),
|
155
141
|
path
|
156
|
-
).stdout.
|
142
|
+
).stdout.split(/(?=[0-9a-f]{40})/m).map do |t|
|
143
|
+
lines = t.split("\n")
|
144
|
+
[
|
145
|
+
lines[0],
|
146
|
+
lines.drop(2).map do |n|
|
147
|
+
n.split(/\s+/).take(2).map(&:to_i).inject(:+)
|
148
|
+
end.inject(:+) || 0
|
149
|
+
]
|
150
|
+
end
|
157
151
|
end
|
158
152
|
|
159
|
-
def
|
160
|
-
|
153
|
+
def sum(hashes, sha)
|
154
|
+
hashes.drop_while { |c| c[0] != sha }.map { |c| c[1] }.inject(:+) || 0
|
161
155
|
end
|
162
156
|
|
163
157
|
def issues(commits)
|
158
|
+
return @issues unless @issues.nil?
|
164
159
|
dates = if @uri.include?('github.com')
|
165
160
|
client = if @opts[:login]
|
166
161
|
Octokit::Client.new(login: @opts[:login], password: @opts[:password])
|
@@ -172,13 +167,23 @@ module TDX
|
|
172
167
|
else
|
173
168
|
@uri.gsub(%r{^https://github\.com/|\.git$}, '')
|
174
169
|
end
|
175
|
-
list =
|
170
|
+
list = []
|
171
|
+
p = 1
|
172
|
+
loop do
|
173
|
+
page = client.list_issues(
|
174
|
+
repo, state: 'all', page: p
|
175
|
+
).map(&:created_at)
|
176
|
+
break if page.empty?
|
177
|
+
list.concat(page)
|
178
|
+
puts "+#{page.length}/#{list.size} issues from GitHub"
|
179
|
+
p += 1
|
180
|
+
end
|
176
181
|
puts "Loaded #{list.length} issues from GitHub repo '#{repo}'"
|
177
182
|
list
|
178
183
|
else
|
179
184
|
[]
|
180
185
|
end
|
181
|
-
commits.map do |sha, date|
|
186
|
+
@issues = commits.map do |sha, date|
|
182
187
|
iso = Time.parse(date)
|
183
188
|
[sha, dates.select { |d| d < iso }.size]
|
184
189
|
end.to_h
|
data/lib/tdx/exec.rb
CHANGED
@@ -36,11 +36,14 @@ module TDX
|
|
36
36
|
def initialize(cmd, dir = '.')
|
37
37
|
@cmd = cmd
|
38
38
|
@dir = dir
|
39
|
+
@log = false
|
39
40
|
end
|
40
41
|
|
41
42
|
def stdout
|
42
|
-
|
43
|
+
puts "+ #{@cmd}" if @log
|
44
|
+
out = `cd #{@dir} && #{@cmd}`
|
43
45
|
raise "This one failed: #{@cmd}" unless $CHILD_STATUS.exitstatus == 0
|
46
|
+
puts out if @log
|
44
47
|
out
|
45
48
|
end
|
46
49
|
end
|
data/lib/tdx/version.rb
CHANGED
data/tdx.gemspec
CHANGED
@@ -51,7 +51,6 @@ Gem::Specification.new do |s|
|
|
51
51
|
s.add_development_dependency 'cucumber', '1.3.17'
|
52
52
|
s.add_development_dependency 'coveralls', '0.7.2'
|
53
53
|
s.add_development_dependency 'rubocop', '0.41.2'
|
54
|
-
s.add_development_dependency 'hoc', '0.8'
|
55
54
|
s.add_development_dependency 'rubocop-rspec', '1.5.1'
|
56
55
|
s.add_development_dependency 'minitest', '5.10.1'
|
57
56
|
end
|
data/test/test__helper.rb
CHANGED
data/test/test_tdx.rb
CHANGED
@@ -41,6 +41,7 @@ class TestPDD < Minitest::Test
|
|
41
41
|
git config user.email yegor256@gmail.com
|
42
42
|
git config user.name 'Mr. Tester'
|
43
43
|
echo 'a = 1' > 1.rb && git add 1.rb && git commit -qam '1'
|
44
|
+
rm 1.rb
|
44
45
|
echo '<?php b = 2' > 2.php && git add 2.php && git commit -qam '2'
|
45
46
|
mkdir tests
|
46
47
|
echo 'c = 3' > tests/3.py && git add tests/3.py && git commit -qam '3'
|
@@ -58,7 +59,7 @@ class TestPDD < Minitest::Test
|
|
58
59
|
assert(
|
59
60
|
TDX::Base.new(
|
60
61
|
'https://github.com/yegor256/empty.git',
|
61
|
-
opts(['--tests', 'src/test/**/*'
|
62
|
+
opts(['--tests', 'src/test/**/*'])
|
62
63
|
).svg.include?('<path ')
|
63
64
|
)
|
64
65
|
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.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.41.2
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: hoc
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.8'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.8'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rubocop-rspec
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|