code_owners 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -13
- data/lib/code_owners.rb +28 -8
- data/lib/code_owners/version.rb +1 -1
- data/spec/code_owners_spec.rb +45 -12
- 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: b742a1fbaa41ae70ad7acc4f258ce685517c74d91855fe554ce29fbb02ca9d99
|
4
|
+
data.tar.gz: 9535aa63120da63e000b8fee5500d696e9d0ee097a12a9bfb052aab5f6b2fb00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2bed6c4f9a8991d6319b31b9d41e6fddc63bdb9cb584a6629106f90514944384f9d67a18134a0afd3c68ff13fb46c8c994af08ad8a1cfebec040d360343ca4f
|
7
|
+
data.tar.gz: bad817126846774d0e62706229351b2abd189bfeb570d16d994d2e01cdc7998bee78dab90979f41fcb3546824f744714a644c28fcc09fe0e8bfb78a2ba29d2b0
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code_owners (1.0.
|
4
|
+
code_owners (1.0.6)
|
5
5
|
rake
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.3)
|
11
|
-
rake (12.3.
|
12
|
-
rspec (3.
|
13
|
-
rspec-core (~> 3.
|
14
|
-
rspec-expectations (~> 3.
|
15
|
-
rspec-mocks (~> 3.
|
16
|
-
rspec-core (3.
|
17
|
-
rspec-support (~> 3.
|
18
|
-
rspec-expectations (3.
|
11
|
+
rake (12.3.3)
|
12
|
+
rspec (3.8.0)
|
13
|
+
rspec-core (~> 3.8.0)
|
14
|
+
rspec-expectations (~> 3.8.0)
|
15
|
+
rspec-mocks (~> 3.8.0)
|
16
|
+
rspec-core (3.8.2)
|
17
|
+
rspec-support (~> 3.8.0)
|
18
|
+
rspec-expectations (3.8.4)
|
19
19
|
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
-
rspec-support (~> 3.
|
21
|
-
rspec-mocks (3.
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-mocks (3.8.1)
|
22
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.
|
24
|
-
rspec-support (3.
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-support (3.8.2)
|
25
25
|
|
26
26
|
PLATFORMS
|
27
27
|
ruby
|
data/lib/code_owners.rb
CHANGED
@@ -13,14 +13,22 @@ module CodeOwners
|
|
13
13
|
# -v -> verbose, outputs details about the matching pattern (if any) for each given pathname
|
14
14
|
# -n -> non-matching, shows given paths which don't match any pattern
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def log(message)
|
17
|
+
puts message
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
+
def ownerships
|
21
|
+
patterns = pattern_owners
|
22
|
+
git_owner_info(patterns.map { |p| p[0] }).map do |line, pattern, file|
|
20
23
|
if line.empty?
|
21
|
-
{ file: file, owner: "UNOWNED" }
|
24
|
+
{ file: file, owner: "UNOWNED", line: nil, pattern: nil }
|
22
25
|
else
|
23
|
-
{
|
26
|
+
{
|
27
|
+
file: file,
|
28
|
+
owner: patterns.fetch(line.to_i-1)[1],
|
29
|
+
line: line,
|
30
|
+
pattern: pattern
|
31
|
+
}
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
@@ -35,11 +43,23 @@ module CodeOwners
|
|
35
43
|
end
|
36
44
|
|
37
45
|
# read the github file and spit out a slightly formatted list of patterns and their owners
|
46
|
+
# Empty/invalid/commented lines are still included in order to preserve line numbering
|
38
47
|
def pattern_owners
|
39
48
|
codeowner_path = search_codeowners_file
|
40
|
-
|
41
|
-
|
42
|
-
|
49
|
+
patterns = []
|
50
|
+
File.read(codeowner_path).split("\n").each_with_index { |line, i|
|
51
|
+
path_owner = line.split(/\s+@/, 2)
|
52
|
+
if line.match(/^\s*(?:#.*)?$/)
|
53
|
+
patterns.push ['', ''] # Comment/empty line
|
54
|
+
elsif path_owner.length != 2 || (path_owner[0].empty? && !path_owner[1].empty?)
|
55
|
+
log "Parse error line #{(i+1).to_s}: \"#{line}\""
|
56
|
+
patterns.push ['', ''] # Invalid line
|
57
|
+
else
|
58
|
+
path_owner[1] = '@'+path_owner[1]
|
59
|
+
patterns.push path_owner
|
60
|
+
end
|
61
|
+
}
|
62
|
+
return patterns
|
43
63
|
end
|
44
64
|
|
45
65
|
def git_owner_info(patterns)
|
data/lib/code_owners/version.rb
CHANGED
data/spec/code_owners_spec.rb
CHANGED
@@ -1,38 +1,71 @@
|
|
1
1
|
require 'code_owners'
|
2
|
+
require 'tmpdir'
|
2
3
|
|
3
|
-
RSpec.describe CodeOwners do
|
4
|
+
RSpec.describe CodeOwners do |rspec|
|
4
5
|
describe ".ownerships" do
|
5
6
|
it "assigns owners to things" do
|
6
|
-
expect(CodeOwners).to receive(:pattern_owners).and_return([["pat1", "own1"], ["pat2", "own2"], ["pat3", "own3"]])
|
7
|
+
expect(CodeOwners).to receive(:pattern_owners).and_return([["pat1", "own1"], ["pat2*", "own2"], ["pat3", "own3"]])
|
7
8
|
expect(CodeOwners).to receive(:git_owner_info).and_return(
|
8
9
|
[
|
9
|
-
["2", "
|
10
|
+
["2", "pat2*", "pat2file"],
|
10
11
|
["", "", "unowned/file"]
|
11
12
|
]
|
12
13
|
)
|
13
14
|
expect(CodeOwners.ownerships).to eq(
|
14
15
|
[
|
15
|
-
{ file: "
|
16
|
-
{ file: "unowned/file",
|
16
|
+
{ file: "pat2file", owner: "own2", line: "2", pattern: "pat2*" },
|
17
|
+
{ file: "unowned/file", owner: "UNOWNED", line: nil, pattern: nil }
|
17
18
|
]
|
18
19
|
)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
describe ".pattern_owners" do
|
24
|
+
around(:each) do |example|
|
25
|
+
Dir.mktmpdir { |d|
|
26
|
+
@d = d
|
27
|
+
f = File.new(File.join(d, 'CODEOWNERS'), 'w+')
|
28
|
+
f.write <<-CODEOWNERS
|
29
|
+
lib/* @jcheatham
|
30
|
+
some/path/** @someoneelse
|
31
|
+
other/path/* @someoneelse @anotherperson
|
32
|
+
invalid/codeowners/line
|
33
|
+
@AnotherInvalidLine
|
34
|
+
#comment-line (empty line next)
|
35
|
+
|
36
|
+
# another comment line
|
37
|
+
CODEOWNERS
|
38
|
+
f.close
|
39
|
+
example.run
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
23
43
|
it "returns a list of patterns and owners" do
|
24
|
-
|
25
|
-
expect(
|
26
|
-
|
44
|
+
expect(CodeOwners).to receive(:current_repo_path).and_return(@d)
|
45
|
+
expect(CodeOwners).to receive(:log).twice
|
46
|
+
pattern_owners = CodeOwners.pattern_owners
|
47
|
+
expect(pattern_owners).to include(["other/path/*", "@someoneelse @anotherperson"])
|
27
48
|
end
|
28
49
|
|
29
50
|
it "works when invoked in a repo's subdirectory" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
51
|
+
expect(CodeOwners).to receive(:current_repo_path).and_return(@d)
|
52
|
+
expect(CodeOwners).to receive(:log).twice
|
53
|
+
subdir = File.join(@d, 'spec')
|
54
|
+
Dir.mkdir(subdir)
|
55
|
+
Dir.chdir(subdir) do
|
56
|
+
pattern_owners = CodeOwners.pattern_owners
|
57
|
+
expect(pattern_owners).to include(["lib/*", "@jcheatham"])
|
34
58
|
end
|
35
59
|
end
|
60
|
+
|
61
|
+
it "prints validation errors and skips lines that aren't the expected format" do
|
62
|
+
expect(CodeOwners).to receive(:current_repo_path).and_return(@d)
|
63
|
+
expect(CodeOwners).to receive(:log).with("Parse error line 4: \"invalid/codeowners/line \"")
|
64
|
+
expect(CodeOwners).to receive(:log).with("Parse error line 5: \" @AnotherInvalidLine\"")
|
65
|
+
pattern_owners = CodeOwners.pattern_owners
|
66
|
+
expect(pattern_owners).not_to include(["", "@AnotherInvalidLine"])
|
67
|
+
expect(pattern_owners).to include(["", ""])
|
68
|
+
end
|
36
69
|
end
|
37
70
|
|
38
71
|
describe ".git_owner_info" do
|