tdx 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -1
- data/bin/tdx +16 -44
- data/features/cli.feature +1 -2
- data/lib/tdx/base.rb +56 -15
- data/lib/tdx/version.rb +1 -1
- data/tdx.gemspec +3 -1
- data/test/test_tdx.rb +15 -7
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b7cfed6e48c402e1cedd1ab7ce10c236ebeacf
|
4
|
+
data.tar.gz: 637915bd109fd8cdf192ac58f3019cf114dc3ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357dbf0825dd394eb54c29a6ed89dedaa5d076f16cf5c5e3e2130bceb1ac4963fe389b2718f6f5a83f41da96527e662beb01063074ef42599b4181b7de7c8eb9
|
7
|
+
data.tar.gz: 7c79c8861cfb785ecca4d1da8dbe76675be1e730ffa2530d86a868feb81b468b4abd890ffeed38bcec8dacbe4d95ece15f567bca4ed550ec42f638e8badbd3d1
|
data/.rubocop.yml
CHANGED
@@ -6,4 +6,12 @@ Metrics/MethodLength:
|
|
6
6
|
Metrics/ClassLength:
|
7
7
|
Max: 150
|
8
8
|
Metrics/AbcSize:
|
9
|
-
Max:
|
9
|
+
Max: 50
|
10
|
+
Style/MultilineMethodCallIndentation:
|
11
|
+
Enabled: false
|
12
|
+
Style/IndentationWidth:
|
13
|
+
Enabled: false
|
14
|
+
Style/ElseAlignment:
|
15
|
+
Enabled: false
|
16
|
+
Lint/EndAlignment:
|
17
|
+
Enabled: false
|
data/bin/tdx
CHANGED
@@ -28,46 +28,17 @@ require 'tdx'
|
|
28
28
|
|
29
29
|
args = ARGV
|
30
30
|
|
31
|
-
opts = Slop.parse(args, strict: true, help: true) do
|
32
|
-
banner "Usage (#{TDX::VERSION}): tdx [options]"
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
'
|
37
|
-
'Repository URI, e.g. "git@github.com:yegor256/tdx.git"',
|
38
|
-
type: String,
|
39
|
-
argument: :required,
|
40
|
-
limit: 1
|
41
|
-
)
|
42
|
-
on(
|
43
|
-
'tests',
|
31
|
+
opts = Slop.parse(args, strict: true, help: true) do |o|
|
32
|
+
o.banner = "Usage (#{TDX::VERSION}): tdx [options] <GitHub URI> <SVG path>"
|
33
|
+
o.bool '-h', '--help', 'Show usage summary'
|
34
|
+
o.bool '-v', '--version', 'Show current version'
|
35
|
+
o.array(
|
36
|
+
'--tests',
|
44
37
|
'Comma-separated list of relative paths with test-related files',
|
45
|
-
|
46
|
-
argument: :required,
|
47
|
-
limit: 1
|
48
|
-
)
|
49
|
-
on(
|
50
|
-
'login',
|
51
|
-
'GitHub login',
|
52
|
-
argument: :required,
|
53
|
-
type: String,
|
54
|
-
limit: 1
|
55
|
-
)
|
56
|
-
on(
|
57
|
-
'password',
|
58
|
-
'GitHub password',
|
59
|
-
argument: :required,
|
60
|
-
type: String,
|
61
|
-
limit: 1
|
62
|
-
)
|
63
|
-
on(
|
64
|
-
's',
|
65
|
-
'svg',
|
66
|
-
'Full path of the SVG file to generate (STDOUT otherwise)',
|
67
|
-
argument: :required,
|
68
|
-
type: String,
|
69
|
-
limit: 1
|
38
|
+
delimiter: ','
|
70
39
|
)
|
40
|
+
o.string '--login', 'GitHub login'
|
41
|
+
o.string '--password', 'GitHub password'
|
71
42
|
end
|
72
43
|
|
73
44
|
if opts.help?
|
@@ -80,11 +51,12 @@ if opts.version?
|
|
80
51
|
exit
|
81
52
|
end
|
82
53
|
|
54
|
+
if opts.arguments.length < 2
|
55
|
+
puts 'URI and SVG path are required'
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
|
83
59
|
Encoding.default_external = Encoding::UTF_8
|
84
60
|
Encoding.default_internal = Encoding::UTF_8
|
85
|
-
output = TDX::Base.new(opts).svg
|
86
|
-
|
87
|
-
File.new(opts[:svg], 'w') << output
|
88
|
-
else
|
89
|
-
puts output
|
90
|
-
end
|
61
|
+
output = TDX::Base.new(opts.arguments[0], opts).svg
|
62
|
+
File.new(opts.arguments[1], 'w') << output
|
data/features/cli.feature
CHANGED
@@ -13,8 +13,7 @@ Feature: Command Line Processing
|
|
13
13
|
|
14
14
|
Scenario: Simple SVG is built
|
15
15
|
Given I have a Git repository in ./repo
|
16
|
-
When I run bin/tdx with "
|
17
|
-
Then Stdout is empty
|
16
|
+
When I run bin/tdx with "file://$(pwd)/repo pic.svg"
|
18
17
|
Then Exit code is zero
|
19
18
|
And SVG is valid in "pic.svg"
|
20
19
|
|
data/lib/tdx/base.rb
CHANGED
@@ -20,8 +20,11 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
+
require 'date'
|
23
24
|
require 'yaml'
|
25
|
+
require 'octokit'
|
24
26
|
require 'fileutils'
|
27
|
+
require 'English'
|
25
28
|
|
26
29
|
# TDX main module.
|
27
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -30,12 +33,13 @@ require 'fileutils'
|
|
30
33
|
module TDX
|
31
34
|
# Base class
|
32
35
|
class Base
|
33
|
-
def initialize(opts)
|
36
|
+
def initialize(uri, opts)
|
37
|
+
@uri = uri
|
34
38
|
@opts = opts
|
35
39
|
end
|
36
40
|
|
37
41
|
def svg
|
38
|
-
dat = Tempfile.new('tdx
|
42
|
+
dat = Tempfile.new('tdx')
|
39
43
|
version = `git --version`.split(/ /)[2]
|
40
44
|
raise "git version #{version} is too old, upgrade it to 2.0+" unless
|
41
45
|
Gem::Version.new(version) >= Gem::Version.new('2.0')
|
@@ -45,13 +49,17 @@ module TDX
|
|
45
49
|
.split(/\n/)
|
46
50
|
.map { |c| c.split(' ') }
|
47
51
|
issues = issues(commits)
|
52
|
+
puts "Date\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA"
|
48
53
|
commits.each do |sha, date|
|
49
54
|
`cd "#{path}" && git checkout --quiet #{sha}`
|
50
|
-
|
51
|
-
|
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\
|
57
|
+
#{loc(path)}\t#{issues[sha]}\t#{sha[0, 7]}"
|
58
|
+
dat << "#{line}\n"
|
59
|
+
puts line
|
52
60
|
end
|
53
61
|
dat.close
|
54
|
-
svg = Tempfile.new('tdx
|
62
|
+
svg = Tempfile.new('tdx')
|
55
63
|
gpi = [
|
56
64
|
"set output \"#{svg.path}\"",
|
57
65
|
'set terminal svg size 700, 260',
|
@@ -64,10 +72,17 @@ module TDX
|
|
64
72
|
'set autoscale',
|
65
73
|
'set style fill solid',
|
66
74
|
'set boxwidth 0.75 relative',
|
67
|
-
|
68
|
-
|
75
|
+
[
|
76
|
+
"plot \"#{dat.path}\" using 1:2 with boxes",
|
77
|
+
'title "Test HoC" linecolor rgb "#81b341"',
|
78
|
+
', "" using 1:3 with boxes title "HoC" linecolor rgb "red"',
|
79
|
+
', "" using 1:4 with boxes title "Files" linecolor rgb "black"',
|
80
|
+
', "" using 1:5 with boxes title "LoC" linecolor rgb "cyan"',
|
81
|
+
', "" using 1:6 with boxes title "Issues" linecolor rgb "orange"'
|
82
|
+
].join(' ')
|
69
83
|
]
|
70
|
-
`gnuplot -e '#{gpi.join(';')}'
|
84
|
+
`gnuplot -e '#{gpi.join('; ')}'`
|
85
|
+
raise 'Failed to run Gnuplot' unless $CHILD_STATUS.exitstatus == 0
|
71
86
|
FileUtils.rm_rf(path)
|
72
87
|
File.delete(dat)
|
73
88
|
xml = File.read(svg)
|
@@ -79,7 +94,12 @@ title \"Test HoC\" linecolor rgb \"#81b341\""
|
|
79
94
|
|
80
95
|
def checkout
|
81
96
|
dir = Dir.mktmpdir
|
82
|
-
`cd #{dir} && git clone --quiet #{@
|
97
|
+
`cd #{dir} && git clone --quiet #{@uri} .`
|
98
|
+
raise 'Failed to clone repository' unless $CHILD_STATUS.exitstatus == 0
|
99
|
+
size = Dir.glob(File.join(dir, '**/*'))
|
100
|
+
.map(&:size)
|
101
|
+
.inject(0) { |a, e| a + e }
|
102
|
+
puts "Cloned #{@uri} (#{size / 1024}Kb) into temporary directory"
|
83
103
|
dir
|
84
104
|
end
|
85
105
|
|
@@ -88,7 +108,8 @@ title \"Test HoC\" linecolor rgb \"#81b341\""
|
|
88
108
|
end
|
89
109
|
|
90
110
|
def loc(path)
|
91
|
-
cloc = `cd "#{path}" && cloc . --yaml --quiet
|
111
|
+
cloc = `cd "#{path}" && cloc . --yaml --quiet`
|
112
|
+
raise 'Failed to run cloc' unless $CHILD_STATUS.exitstatus == 0
|
92
113
|
yaml = YAML.load(cloc)
|
93
114
|
if yaml
|
94
115
|
yaml['SUM']['code']
|
@@ -98,17 +119,37 @@ title \"Test HoC\" linecolor rgb \"#81b341\""
|
|
98
119
|
end
|
99
120
|
|
100
121
|
def hoc(path)
|
101
|
-
`cd "#{path}" && hoc`
|
122
|
+
hoc = `cd "#{path}" && hoc`
|
123
|
+
raise 'Failed to run hoc' unless $CHILD_STATUS.exitstatus == 0
|
124
|
+
hoc
|
102
125
|
end
|
103
126
|
|
104
127
|
def tests(path)
|
105
|
-
`cd "#{path}" && hoc`
|
128
|
+
hoc = `cd "#{path}" && hoc`
|
129
|
+
raise 'Failed to run hoc' unless $CHILD_STATUS.exitstatus == 0
|
130
|
+
hoc
|
106
131
|
end
|
107
132
|
|
108
133
|
def issues(commits)
|
109
|
-
dates =
|
110
|
-
|
111
|
-
|
134
|
+
dates = if @uri.include?('github.com')
|
135
|
+
client = if @opts[:login]
|
136
|
+
Octokit::Client.new(login: @opts[:login], password: @opts[:password])
|
137
|
+
else
|
138
|
+
Octokit::Client.new
|
139
|
+
end
|
140
|
+
repo = if @uri.start_with?('git@')
|
141
|
+
@uri.gsub(/^git@github\.com:|\.git$/, '')
|
142
|
+
else
|
143
|
+
@uri.gsub(%r{^https://github\.com/|\.git$}, '')
|
144
|
+
end
|
145
|
+
client.list_issues(repo, state: :all).map(&:created_at)
|
146
|
+
else
|
147
|
+
[]
|
148
|
+
end
|
149
|
+
commits.map do |sha, date|
|
150
|
+
iso = Time.parse(date)
|
151
|
+
[sha, dates.select { |d| d < iso }.size]
|
152
|
+
end.to_h
|
112
153
|
end
|
113
154
|
end
|
114
155
|
end
|
data/lib/tdx/version.rb
CHANGED
data/tdx.gemspec
CHANGED
@@ -44,11 +44,13 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
45
45
|
s.rdoc_options = ['--charset=UTF-8']
|
46
46
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
47
|
-
s.add_runtime_dependency 'slop', '~>
|
47
|
+
s.add_runtime_dependency 'slop', '~>4.4.1'
|
48
|
+
s.add_runtime_dependency 'octokit', '~>4.6.2'
|
48
49
|
s.add_development_dependency 'rake', '12.0.0'
|
49
50
|
s.add_development_dependency 'cucumber', '1.3.17'
|
50
51
|
s.add_development_dependency 'coveralls', '0.7.2'
|
51
52
|
s.add_development_dependency 'rubocop', '0.41.2'
|
53
|
+
s.add_development_dependency 'hoc', '0.8'
|
52
54
|
s.add_development_dependency 'rubocop-rspec', '1.5.1'
|
53
55
|
s.add_development_dependency 'minitest', '5.10.1'
|
54
56
|
s.add_development_dependency 'nokogiri', '1.7.0.1'
|
data/test/test_tdx.rb
CHANGED
@@ -35,7 +35,6 @@ class TestPDD < Minitest::Test
|
|
35
35
|
Dir.mktmpdir 'test' do |dir|
|
36
36
|
opts = opts(
|
37
37
|
[
|
38
|
-
'--repo', "file:///#{File.join(dir, 'repo')}",
|
39
38
|
'--tests', 'tests'
|
40
39
|
]
|
41
40
|
)
|
@@ -51,18 +50,27 @@ class TestPDD < Minitest::Test
|
|
51
50
|
mkdir tests
|
52
51
|
echo 'c = 3' > tests/3.py && git add tests/3.py && git commit -qam '3'
|
53
52
|
")
|
54
|
-
assert(
|
53
|
+
assert(
|
54
|
+
TDX::Base.new(
|
55
|
+
"file:///#{File.join(dir, 'repo')}", opts
|
56
|
+
).svg.include?('<path ')
|
57
|
+
)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
61
|
+
def test_real_github_repo
|
62
|
+
assert(
|
63
|
+
TDX::Base.new(
|
64
|
+
'https://github.com/yegor256/tdx.git', opts([])
|
65
|
+
).svg.include?('<path ')
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
58
69
|
private
|
59
70
|
|
60
71
|
def opts(args)
|
61
|
-
Slop.parse args do
|
62
|
-
|
63
|
-
on 's', 'svg', argument: :required
|
64
|
-
on 'r', 'repo', argument: :required
|
65
|
-
on 't', 'tests', argument: :required
|
72
|
+
Slop.parse args do |o|
|
73
|
+
o.string '-t', '--tests', argument: :required
|
66
74
|
end
|
67
75
|
end
|
68
76
|
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.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.4.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.4.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.6.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.6.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - '='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: 0.41.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: hoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rubocop-rspec
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|