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 +4 -4
- data/Gemfile.lock +13 -13
- data/lib/code_owners/version.rb +1 -1
- data/lib/code_owners.rb +27 -16
- data/spec/code_owners_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42ad83e6c56f3bb34904d52dde4eb0f689fde59ea59868ecd4c428f3f13c8762
|
4
|
+
data.tar.gz: f8abb4f85d6fdf586432d047d9c24a521ea4411853a4a36e88de57556698d6a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
11
|
+
diff-lcs (1.5.0)
|
12
12
|
pathspec (0.2.1)
|
13
13
|
rake (13.0.6)
|
14
|
-
rspec (3.
|
15
|
-
rspec-core (~> 3.
|
16
|
-
rspec-expectations (~> 3.
|
17
|
-
rspec-mocks (~> 3.
|
18
|
-
rspec-core (3.
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-expectations (3.
|
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.
|
23
|
-
rspec-mocks (3.
|
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.
|
26
|
-
rspec-support (3.
|
25
|
+
rspec-support (~> 3.11.0)
|
26
|
+
rspec-support (3.11.0)
|
27
27
|
|
28
28
|
PLATFORMS
|
29
29
|
ruby
|
data/lib/code_owners/version.rb
CHANGED
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
|
-
|
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(
|
24
|
+
ownerships_by_ruby(patowns, files, opts)
|
25
25
|
else
|
26
|
-
ownerships_by_gitignore(
|
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(
|
82
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
##############
|
data/spec/code_owners_spec.rb
CHANGED
@@ -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
|