git-recommend 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/git-test +1 -1
  3. data/lib/git_test.rb +29 -20
  4. data/lib/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7396b42cb2f6d31e427214554481e4425f20e5b7
4
- data.tar.gz: 4ef7cbba5c84eaef068e1c5c2d120e7cc09bab19
3
+ metadata.gz: 7dcb382ae28e749803477ed0a508f0e86ed8768e
4
+ data.tar.gz: b626e2449e9edb8b355122ae08ce944cada99d7e
5
5
  SHA512:
6
- metadata.gz: e277ce21a284fc256370aebcb744f4d47dc5516930ce75817763439b4dd6dff8498214c7446d282902ce7945b4cee1aac5d9679b203792a59925ee35593c9ae7
7
- data.tar.gz: df30d9cf8bb9d86899fd2c73d0de86613789b444ddc6394eb24caa9754890dfd651aa4406cb24dd05886cb54cd67363e51f29ae58fcd46704993855d41c15ebd
6
+ metadata.gz: 21d0b9d197c7f56252873cf9e626d2dd86e341e7e1bb9cb7502b58329e16754db06c96da5e4e16d74d9679968cd9e5a02133a3e6d4cf30b88bf464e46ac58d8f
7
+ data.tar.gz: 0bc7ce53718967075d7ed586627c314b5743e731ddf9604ed12edd7075bd5efab370ac6c0b65a1d6b9d2846b7ae296836449d90ff39d91faed54dad560717c88
data/bin/git-test CHANGED
@@ -1,4 +1,4 @@
1
- #impacted_items!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
  require_relative '../lib/helper.rb'
3
3
 
4
4
  GitTest.start(ARGV)
data/lib/git_test.rb CHANGED
@@ -24,13 +24,14 @@ class GitTest < Thor
24
24
  # find relevant tests
25
25
  [LHS,RHS].each do |side|
26
26
  tests = (row["#{side}_tested_by"].nil? ? [] : row["#{side}_tested_by"].split(","))
27
+ file = row[side]
27
28
  tests.each do |test|
28
- coverage[side] << row[side]
29
+ coverage[side] << file
29
30
  if test_plan[test].nil?
30
- test_plan[test] = {'cg' => 0, LHS => 0, RHS => 0}
31
+ test_plan[test] = {'cg' => 0, LHS => Set.new, RHS => Set.new}
31
32
  end
32
33
  test_plan[test]['cg'] += support
33
- test_plan[test][side] += 1
34
+ test_plan[test][side] << file
34
35
  end
35
36
  end
36
37
  end
@@ -48,8 +49,8 @@ class GitTest < Thor
48
49
  end
49
50
  # print testplan to stdout
50
51
  $stdout.puts "test,impact,#{LHS}_covered,#{RHS}_covered"
51
- test_plan.sort_by {|k,v| [v[LHS],v[RHS]].max}.each do |test,v|
52
- $stdout.puts "#{test},#{v['cg']},#{v[LHS]},#{v[RHS]}"
52
+ test_plan.sort_by {|k,v| [v[LHS].size,v[RHS].size].max}.each do |test,v|
53
+ $stdout.puts "#{test},#{v['cg']},#{v[LHS].size},#{v[RHS].size}"
53
54
  end
54
55
  end
55
56
 
@@ -59,6 +60,9 @@ class GitTest < Thor
59
60
  def join
60
61
  begin
61
62
  mapping = CSV.read(options[:mapping], headers: true, skip_lines: /#/)
63
+ mapping.each do |row|
64
+ row["pattern"] = Regexp.new(row["pattern"], Regexp::IGNORECASE)
65
+ end
62
66
  rescue CSV::MalformedCSVError, ArgumentError => e
63
67
  $stderr.puts "An error occured when parsing the mapping file '#{options[:mapping]}:\n #{e}"
64
68
  exit 1
@@ -71,29 +75,34 @@ class GitTest < Thor
71
75
  exit 1
72
76
  end
73
77
 
78
+ pattern_matched = Hash.new
74
79
 
75
80
  # print header
76
- CSV {|r| r << %w(#{LHS} #{RHS} support #{LHS}_tested_by #{RHS}_tested_by)}
81
+ CSV {|r| r << %W(#{LHS} #{RHS} support #{LHS}_tested_by #{RHS}_tested_by)}
77
82
  change_rec.each do |row|
78
- lhs = row['lhs']
79
- rhs = row['rhs']
80
83
  support = row["support"].to_r.to_f
81
- # find relevant tests
82
- lhs_tests = []
83
- rhs_tests = []
84
- mapping.each do |mapping_row|
85
- pattern = Regexp.new(mapping_row["pattern"], Regexp::IGNORECASE)
86
- test = mapping_row["test"]
87
- if lhs =~ pattern
88
- lhs_tests << test
89
- end
90
84
 
91
- if rhs =~ pattern
92
- rhs_tests << test
85
+ tests = {'lhs': Set.new, 'rhs': Set.new}
86
+
87
+ ['lhs','rhs'].each do |side|
88
+ file = row[side]
89
+ # check if the files has already been mapped
90
+ if pattern_matched[file].nil?
91
+ pattern_matched[file] = []
92
+ # iterate through mapping file to find matching tests
93
+ mapping.each do |mapping_row|
94
+ pattern = mapping_row["pattern"]
95
+ test = mapping_row["test"]
96
+ if file =~ pattern
97
+ pattern_matched[file] << test
98
+ end
99
+ end
93
100
  end
101
+ tests[side] = pattern_matched[file]
94
102
  end
103
+
95
104
  # print new row
96
- CSV {|r| r << [lhs, rhs, support, (lhs_tests.empty? ? nil : lhs_tests.join(",")), (rhs_tests.empty? ? nil : rhs_tests.join(","))]}
105
+ CSV {|r| r << [row['lhs'], row['rhs'], support, (tests['lhs'].empty? ? nil : tests['lhs'].join(",")), (tests['rhs'].empty? ? nil : tests['rhs'].join(","))]}
97
106
  end
98
107
  end
99
108
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Recommend
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-recommend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Rolfsnes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor