code_owners 1.0.6 → 1.0.9
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 +5 -5
- data/Gemfile.lock +3 -3
- data/README.md +12 -6
- data/bin/code_owners +35 -0
- data/code_owners.gemspec +2 -2
- data/lib/code_owners/version.rb +1 -1
- data/lib/code_owners.rb +8 -2
- data/spec/code_owners_spec.rb +38 -2
- data/spec/files/file name.txt +1 -0
- data/spec/files//342/230/203.txt +1 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: add8d9474667ea07ea6ad3e207e9a0e085109ac9
|
4
|
+
data.tar.gz: 86f55b021ef6314614ac2e5f2a59dfec43adbcd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc09a62ef1d0b86e7a9be070b27c5ed0e21be5b797f29b2597b3c06ffecc8210fd50906319f67028bc8e8a4df3aa2b575ab5ae49a083f2af029f43182d9d074
|
7
|
+
data.tar.gz: 62e13f5c44667eff192eabb510dca677a2088e58ce123e3dbaf4ccd16c8ebf9eb1dffa8125d5524161de36df730b9eea83093776ea6a55fb40c72df6f741eec3
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code_owners (1.0.
|
4
|
+
code_owners (1.0.9)
|
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 (
|
11
|
+
rake (13.0.6)
|
12
12
|
rspec (3.8.0)
|
13
13
|
rspec-core (~> 3.8.0)
|
14
14
|
rspec-expectations (~> 3.8.0)
|
@@ -31,4 +31,4 @@ DEPENDENCIES
|
|
31
31
|
rspec
|
32
32
|
|
33
33
|
BUNDLED WITH
|
34
|
-
1.17.
|
34
|
+
1.17.3
|
data/README.md
CHANGED
@@ -5,6 +5,12 @@ Install
|
|
5
5
|
|
6
6
|
gem install code_owners
|
7
7
|
|
8
|
+
Requirements
|
9
|
+
============
|
10
|
+
|
11
|
+
* Ruby
|
12
|
+
* Git
|
13
|
+
|
8
14
|
Usage
|
9
15
|
=====
|
10
16
|
|
@@ -24,12 +30,12 @@ Development
|
|
24
30
|
|
25
31
|
Maybe put it in a cleanliness test, like:
|
26
32
|
|
27
|
-
```
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
```ruby
|
34
|
+
it "does not introduce new unowned files" do
|
35
|
+
unowned_files = CodeOwners.ownerships.select { |f| f[:owner] == CodeOwners::NO_OWNER }
|
36
|
+
# this number should only decrease, never increase!
|
37
|
+
assert_equal 12345, unowned_files.count, "Claim ownership of your new files in .github/CODEOWNERS to fix this test!"
|
38
|
+
end
|
33
39
|
```
|
34
40
|
|
35
41
|
Author
|
data/bin/code_owners
CHANGED
@@ -1,10 +1,45 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
unless system('git --version > /dev/null')
|
4
|
+
STDERR.puts 'Git does not appear to be installed.'
|
5
|
+
exit 2
|
6
|
+
end
|
7
|
+
|
8
|
+
unless system('git rev-parse --is-inside-work-tree > /dev/null')
|
9
|
+
STDERR.puts 'The current working directory must be a Git repo.'
|
10
|
+
exit 3
|
11
|
+
end
|
12
|
+
|
3
13
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
4
14
|
require 'code_owners'
|
15
|
+
require 'code_owners/version'
|
16
|
+
require 'optparse'
|
17
|
+
|
18
|
+
options = {}
|
19
|
+
OptionParser.new do |opts|
|
20
|
+
opts.banner = "usage: code_owners [options]"
|
21
|
+
opts.on('-u', '--unowned', TrueClass, 'Display unowned files only') do |u|
|
22
|
+
options[:unowned] = u
|
23
|
+
end
|
24
|
+
opts.on('-e', '--error-unowned', TrueClass, 'Exit with error status if any files are unowned') do |e|
|
25
|
+
options[:error_unowned] = e
|
26
|
+
end
|
27
|
+
opts.on('-v', '--version', TrueClass, 'Display the version of the gem') do |_|
|
28
|
+
puts "Version: #{CodeOwners::VERSION}"
|
29
|
+
exit 0
|
30
|
+
end
|
31
|
+
end.parse!
|
5
32
|
|
33
|
+
unowned_error = false
|
6
34
|
CodeOwners.ownerships.each do |ownership_status|
|
7
35
|
owner_info = ownership_status[:owner].dup
|
36
|
+
if owner_info != CodeOwners::NO_OWNER
|
37
|
+
next if options[:unowned]
|
38
|
+
else
|
39
|
+
unowned_error ||= options[:error_unowned]
|
40
|
+
end
|
8
41
|
owner_info += " per line #{ownership_status[:line]}, #{ownership_status[:pattern]}" if owner_info != "UNOWNED"
|
9
42
|
puts "#{ownership_status[:file].ljust(100,' ')} #{owner_info}"
|
10
43
|
end
|
44
|
+
|
45
|
+
exit(unowned_error && 1 || 0)
|
data/code_owners.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new name, CodeOwners::VERSION do |s|
|
|
8
8
|
s.description = "utility gem for .github/CODEOWNERS introspection"
|
9
9
|
s.authors = "Jonathan Cheatham"
|
10
10
|
s.email = "coaxis@gmail.com"
|
11
|
-
s.homepage = "
|
11
|
+
s.homepage = "https://github.com/jcheatham/#{s.name}"
|
12
12
|
s.licenses = "MIT"
|
13
13
|
|
14
|
-
s.files = `git ls-files`.split("\n")
|
14
|
+
s.files = `git -c "core.quotepath=off" ls-files`.split("\n")
|
15
15
|
s.bindir = 'bin'
|
16
16
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
data/lib/code_owners/version.rb
CHANGED
data/lib/code_owners.rb
CHANGED
@@ -2,7 +2,9 @@ require "code_owners/version"
|
|
2
2
|
require "tempfile"
|
3
3
|
|
4
4
|
module CodeOwners
|
5
|
+
NO_OWNER = 'UNOWNED'
|
5
6
|
class << self
|
7
|
+
|
6
8
|
# github's CODEOWNERS rules (https://help.github.com/articles/about-codeowners/) are allegedly based on the gitignore format.
|
7
9
|
# but you can't tell ls-files to ignore tracked files via an arbitrary pattern file
|
8
10
|
# so we need to jump through some hacky git-fu hoops
|
@@ -17,11 +19,15 @@ module CodeOwners
|
|
17
19
|
puts message
|
18
20
|
end
|
19
21
|
|
22
|
+
def file_ownerships
|
23
|
+
Hash[ ownerships.map { |o| [o[:file], o] } ]
|
24
|
+
end
|
25
|
+
|
20
26
|
def ownerships
|
21
27
|
patterns = pattern_owners
|
22
28
|
git_owner_info(patterns.map { |p| p[0] }).map do |line, pattern, file|
|
23
29
|
if line.empty?
|
24
|
-
{ file: file, owner:
|
30
|
+
{ file: file, owner: NO_OWNER, line: nil, pattern: nil }
|
25
31
|
else
|
26
32
|
{
|
27
33
|
file: file,
|
@@ -75,7 +81,7 @@ module CodeOwners
|
|
75
81
|
Tempfile.open('codeowner_patterns') do |file|
|
76
82
|
file.write(patterns.join("\n"))
|
77
83
|
file.rewind
|
78
|
-
`cd #{current_repo_path} && git ls-files | xargs -- git -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n`
|
84
|
+
`cd #{current_repo_path} && git -c \"core.quotepath=off\" ls-files -z | xargs -0 -- git -c \"core.quotepath=off\" -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n`
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
data/spec/code_owners_spec.rb
CHANGED
@@ -2,6 +2,23 @@ require 'code_owners'
|
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
4
|
RSpec.describe CodeOwners do |rspec|
|
5
|
+
describe ".file_ownerships" do
|
6
|
+
it "returns a hash of ownerships keyed by file path" do
|
7
|
+
expect(CodeOwners).to receive(:ownerships).and_return(
|
8
|
+
[
|
9
|
+
{ file: "pat2file", owner: "own2", line: "2", pattern: "pat2*" },
|
10
|
+
{ file: "unowned/file", owner: "UNOWNED", line: nil, pattern: nil }
|
11
|
+
]
|
12
|
+
)
|
13
|
+
expect(CodeOwners.file_ownerships).to eq(
|
14
|
+
{
|
15
|
+
"pat2file" => { file: "pat2file", owner: "own2", line: "2", pattern: "pat2*" },
|
16
|
+
"unowned/file" => { file: "unowned/file", owner: "UNOWNED", line: nil, pattern: nil }
|
17
|
+
}
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
describe ".ownerships" do
|
6
23
|
it "assigns owners to things" do
|
7
24
|
expect(CodeOwners).to receive(:pattern_owners).and_return([["pat1", "own1"], ["pat2*", "own2"], ["pat3", "own3"]])
|
@@ -29,7 +46,7 @@ RSpec.describe CodeOwners do |rspec|
|
|
29
46
|
lib/* @jcheatham
|
30
47
|
some/path/** @someoneelse
|
31
48
|
other/path/* @someoneelse @anotherperson
|
32
|
-
invalid/
|
49
|
+
invalid/code owners/line
|
33
50
|
@AnotherInvalidLine
|
34
51
|
#comment-line (empty line next)
|
35
52
|
|
@@ -60,7 +77,7 @@ CODEOWNERS
|
|
60
77
|
|
61
78
|
it "prints validation errors and skips lines that aren't the expected format" do
|
62
79
|
expect(CodeOwners).to receive(:current_repo_path).and_return(@d)
|
63
|
-
expect(CodeOwners).to receive(:log).with("Parse error line 4: \"invalid/
|
80
|
+
expect(CodeOwners).to receive(:log).with("Parse error line 4: \"invalid/code owners/line\"")
|
64
81
|
expect(CodeOwners).to receive(:log).with("Parse error line 5: \" @AnotherInvalidLine\"")
|
65
82
|
pattern_owners = CodeOwners.pattern_owners
|
66
83
|
expect(pattern_owners).not_to include(["", "@AnotherInvalidLine"])
|
@@ -86,5 +103,24 @@ CODEOWNERS
|
|
86
103
|
expect(raw_ownership.size).to be >= 1
|
87
104
|
expect(raw_ownership).to match(/^(?:.*:\d*:.*\t.*\n)+$/)
|
88
105
|
end
|
106
|
+
|
107
|
+
context "when path includes a space" do
|
108
|
+
it "returns the path in single line" do
|
109
|
+
raw_ownership = CodeOwners.raw_git_owner_info(["/spec/files/*"])
|
110
|
+
expect(raw_ownership).to match(/.+:\d+:.+\tspec\/files\/file name\.txt\n/)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "code_owners" do
|
116
|
+
VERSION_REGEX = /Version: \d+\.\d+\.\d+(-[a-z0-9]+)?/i
|
117
|
+
|
118
|
+
it "prints a version number with the short option" do
|
119
|
+
expect(`bin#{File::SEPARATOR}code_owners -v`).to match VERSION_REGEX
|
120
|
+
end
|
121
|
+
|
122
|
+
it "prints a version number with the short option" do
|
123
|
+
expect(`bin#{File::SEPARATOR}code_owners --version`).to match VERSION_REGEX
|
124
|
+
end
|
89
125
|
end
|
90
126
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This file's name includes a space.
|
@@ -0,0 +1 @@
|
|
1
|
+
☃☃☃☃☃☃☃☃☃
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_owners
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Cheatham
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-03-29 00:00:00.000000000 Z
|
@@ -57,11 +57,13 @@ files:
|
|
57
57
|
- lib/code_owners.rb
|
58
58
|
- lib/code_owners/version.rb
|
59
59
|
- spec/code_owners_spec.rb
|
60
|
-
|
60
|
+
- spec/files/file name.txt
|
61
|
+
- spec/files/☃.txt
|
62
|
+
homepage: https://github.com/jcheatham/code_owners
|
61
63
|
licenses:
|
62
64
|
- MIT
|
63
65
|
metadata: {}
|
64
|
-
post_install_message:
|
66
|
+
post_install_message:
|
65
67
|
rdoc_options: []
|
66
68
|
require_paths:
|
67
69
|
- lib
|
@@ -76,8 +78,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
78
|
- !ruby/object:Gem::Version
|
77
79
|
version: '0'
|
78
80
|
requirements: []
|
79
|
-
|
80
|
-
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.6.14.4
|
83
|
+
signing_key:
|
81
84
|
specification_version: 4
|
82
85
|
summary: ".github/CODEOWNERS introspection utility gem"
|
83
86
|
test_files: []
|