code_owners 2.0.0 → 2.0.1

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
  SHA256:
3
- metadata.gz: baea109754326800382bc8665df1e20634680187a1209f612bcc14f1447a962e
4
- data.tar.gz: 25975f589029d740031c6c14832341a605fa885386be3f88bcb992cb427b1bf0
3
+ metadata.gz: 42ad83e6c56f3bb34904d52dde4eb0f689fde59ea59868ecd4c428f3f13c8762
4
+ data.tar.gz: f8abb4f85d6fdf586432d047d9c24a521ea4411853a4a36e88de57556698d6a1
5
5
  SHA512:
6
- metadata.gz: be4b52ceca387c455f3b597f47c3f61aed0d3c381eb4d52e6f2d9c25311d0505704ebb817af0ab73892521bdb1f804fc3a560bfb49c54e1f62b03bf20fe6b796
7
- data.tar.gz: b31b2929d9023a3609bbd8286b4579ff87c8af5f4a6fc9025ccce9f8bdbddb65c09facf92c7a6873dd20423e925e083de41ba7de8800210ea2cf2b67b749082a
6
+ metadata.gz: 80e88fb5714e128bcb401a8ecd7be79e631c3105c370d7ac275bc2ffd60ac92182b5d6090ad60782cba0cc6af89a60a0758466d4ebc703269ad83ea8d8cf5e4e
7
+ data.tar.gz: fa22fe034e7256b8637564a74803c044e85c675399978e8ccfc4d114b1b88d958501f5143c205d8cc159c40a1f823f269567cf6e22a84df896e5161f6a385113
data/Gemfile.lock CHANGED
@@ -1,29 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code_owners (2.0.0)
4
+ code_owners (2.0.1)
5
5
  pathspec
6
6
  rake
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- diff-lcs (1.3)
11
+ diff-lcs (1.5.0)
12
12
  pathspec (0.2.1)
13
13
  rake (13.0.6)
14
- rspec (3.8.0)
15
- rspec-core (~> 3.8.0)
16
- rspec-expectations (~> 3.8.0)
17
- rspec-mocks (~> 3.8.0)
18
- rspec-core (3.8.2)
19
- rspec-support (~> 3.8.0)
20
- rspec-expectations (3.8.4)
14
+ rspec (3.11.0)
15
+ rspec-core (~> 3.11.0)
16
+ rspec-expectations (~> 3.11.0)
17
+ rspec-mocks (~> 3.11.0)
18
+ rspec-core (3.11.0)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-expectations (3.11.0)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.8.0)
23
- rspec-mocks (3.8.1)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-mocks (3.11.1)
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.8.0)
26
- rspec-support (3.8.2)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-support (3.11.0)
27
27
 
28
28
  PLATFORMS
29
29
  ruby
@@ -1,3 +1,3 @@
1
1
  module CodeOwners
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/code_owners.rb CHANGED
@@ -18,12 +18,12 @@ module CodeOwners
18
18
  # this maps the collection of ownership patterns and owners to actual files
19
19
  def ownerships(opts = {})
20
20
  log("Calculating ownerships for #{opts.inspect}", opts)
21
- patterns = pattern_owners(codeowners_data(opts), opts)
21
+ patowns = pattern_owners(codeowners_data(opts), opts)
22
22
  if opts[:no_git]
23
23
  files = files_to_own(opts)
24
- ownerships_by_ruby(patterns, files, opts)
24
+ ownerships_by_ruby(patowns, files, opts)
25
25
  else
26
- ownerships_by_gitignore(patterns, opts)
26
+ ownerships_by_gitignore(patowns, opts)
27
27
  end
28
28
  end
29
29
 
@@ -78,24 +78,35 @@ module CodeOwners
78
78
  ###############
79
79
  # ruby approach
80
80
 
81
- def ownerships_by_ruby(patterns, files, opts = {})
82
- ownerships = files.map { |f| { file: f, owner: NO_OWNER, line: nil, pattern: nil } }
81
+ def ownerships_by_ruby(patowns, files, opts = {})
82
+ pattern_list = build_ruby_patterns(patowns, opts)
83
+ unowned = { owner: NO_OWNER, line: nil, pattern: nil }
83
84
 
84
- patterns.each_with_index do |(pattern, owner), i|
85
- next if pattern == ""
86
- pattern = pattern.gsub(/\/\*$/, "/**")
87
- spec_pattern = PathSpec::GitIgnoreSpec.new(pattern)
88
- ownerships.each do |o|
89
- next unless spec_pattern.match(o[:file])
90
- o[:owner] = owner
91
- o[:line] = i+1
92
- o[:pattern] = pattern
85
+ files.map do |file|
86
+ last_match = nil
87
+ # have a flag to go through in reverse order as potential optimization?
88
+ # really depends on the data
89
+ pattern_list.each do |p|
90
+ last_match = p if p[:pattern_regex].match(file)
93
91
  end
92
+ (last_match || unowned).dup.tap{|h| h[:file] = file }
94
93
  end
95
-
96
- ownerships
97
94
  end
98
95
 
96
+ def build_ruby_patterns(patowns, opts = {})
97
+ pattern_list = []
98
+ patowns.each_with_index do |(pattern, owner), i|
99
+ next if pattern == ""
100
+ pattern_list << {
101
+ owner: owner,
102
+ line: i+1,
103
+ pattern: pattern,
104
+ # gsub because spec approach needs a little help matching remainder of tree recursively
105
+ pattern_regex: PathSpec::GitIgnoreSpec.new(pattern.gsub(/\/\*$/, "/**"))
106
+ }
107
+ end
108
+ pattern_list
109
+ end
99
110
 
100
111
 
101
112
  ##############
@@ -46,10 +46,10 @@ RSpec.describe CodeOwners do |rspec|
46
46
  results = CodeOwners.ownerships(no_git: true)
47
47
  expect(results).to match_array([
48
48
  {:file=>"zip", :owner=>"UNOWNED", :line=>nil, :pattern=>nil},
49
- {:file=>"foo.rb", :owner=>"own2", :line=>2, :pattern=>"foo*"},
50
- {:file=>"foo/bar.rb", :owner=>"own3", :line=>3, :pattern=>"foo/**"},
51
- {:file=>"foo/bar/baz.rb", :owner=>"own3", :line=>3, :pattern=>"foo/**"},
52
- {:file=>"foo/bar/baz/meow.txt", :owner=>"own3", :line=>3, :pattern=>"foo/**"},
49
+ {:file=>"foo.rb", :owner=>"own2", :line=>2, :pattern=>"foo*", pattern_regex: anything},
50
+ {:file=>"foo/bar.rb", :owner=>"own3", :line=>3, :pattern=>"foo/**", pattern_regex: anything},
51
+ {:file=>"foo/bar/baz.rb", :owner=>"own3", :line=>3, :pattern=>"foo/**", pattern_regex: anything},
52
+ {:file=>"foo/bar/baz/meow.txt", :owner=>"own3", :line=>3, :pattern=>"foo/**", pattern_regex: anything},
53
53
  {:file=>"waffles", :owner=>"UNOWNED", :line=>nil, :pattern=>nil}
54
54
  ])
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_owners
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Cheatham