codeowners-checker 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/codeowners/checker.rb +19 -4
- data/lib/codeowners/checker/version.rb +1 -1
- data/lib/codeowners/checker/whitelist.rb +36 -0
- data/lib/codeowners/cli/main.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6048aab671d2371c50bde29d63d426f7e2f0ef8f29bb7b5ee62517d0e0c872b9
|
4
|
+
data.tar.gz: 416440eb3334d8de4c4e8d24c2d78ff81483bf45b9b91d6558ca803240d1a57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d2d705c35ea5ec8930c1f917c597ebf6d424f08c868f7a251874e97e6c2c1cca7b789fa6a2e7d257d0dffdfbab861932f4a3c784eb3d1fad48f485ef1eae024
|
7
|
+
data.tar.gz: e5b192ef813b86c9e11de1a8a81b2b516f7470422ca22a82f70e4f9f2e0a592b03ceb855bd9b967ed0e5ccb97d299a5efbc0d24fc928a829c525a3721b7bba62
|
data/README.md
CHANGED
@@ -17,6 +17,23 @@ between two git revisions.
|
|
17
17
|
|
18
18
|
It will configure `@owner` as the default owner in the config file.
|
19
19
|
|
20
|
+
#### Whitelist
|
21
|
+
|
22
|
+
If you are just starting to use `codeowners-checker` in your project, you might not have clear ownership defined for all parts of the code. In this case using the checker would be very tedious in the beginning, as it prompts for ownership rules for all files.
|
23
|
+
|
24
|
+
You can still use `codeowners-checker` in this case without the tedium by providing a whitelist. The whitelist contains patterns to ignore when checking files.
|
25
|
+
|
26
|
+
Just place a file called `CODEOWNERS_WHITELIST` next to your `CODEOWNERS` file to enable the whitelist.
|
27
|
+
|
28
|
+
Here is an example:
|
29
|
+
|
30
|
+
```
|
31
|
+
# The format of the file follows the format used by .gitignore
|
32
|
+
|
33
|
+
# ignore files under bin
|
34
|
+
bin/*
|
35
|
+
```
|
36
|
+
For all operations, `codeowners-checker` will ignore files matching the patterns in here.
|
20
37
|
|
21
38
|
### Fetching and validating owners
|
22
39
|
|
@@ -195,6 +212,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
195
212
|
|
196
213
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
197
214
|
|
215
|
+
Have a look at [spec/README.md](./spec/README.md) for more information about what tools are available when writing tests.
|
216
|
+
|
198
217
|
## Contributing
|
199
218
|
|
200
219
|
Bug reports and pull requests are welcome on GitHub at https://github.com/toptal/codeowners-checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/codeowners/checker.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'checker/code_owners'
|
|
7
7
|
require_relative 'checker/file_as_array'
|
8
8
|
require_relative 'checker/group'
|
9
9
|
require_relative 'checker/owners_list'
|
10
|
+
require_relative 'checker/whitelist'
|
10
11
|
|
11
12
|
module Codeowners
|
12
13
|
# Check if code owners are consistent between a git repository and the CODEOWNERS file.
|
@@ -27,7 +28,7 @@ module Codeowners
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def changes_to_analyze
|
30
|
-
@git.diff(@from, @to).name_status
|
31
|
+
@git.diff(@from, @to).name_status.reject(&whitelist)
|
31
32
|
end
|
32
33
|
|
33
34
|
def added_files
|
@@ -39,7 +40,7 @@ module Codeowners
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def changes_for_patterns(patterns)
|
42
|
-
@git.diff(@from, @to).path(patterns).name_status.keys
|
43
|
+
@git.diff(@from, @to).path(patterns).name_status.keys.reject(&whitelist)
|
43
44
|
end
|
44
45
|
|
45
46
|
def patterns_by_owner
|
@@ -74,7 +75,7 @@ module Codeowners
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def pattern_has_files(pattern)
|
77
|
-
@git.ls_files(pattern.gsub(%r{^/}, '')).any?
|
78
|
+
@git.ls_files(pattern.gsub(%r{^/}, '')).reject(&whitelist).any?
|
78
79
|
end
|
79
80
|
|
80
81
|
def defined_owner?(file)
|
@@ -87,6 +88,18 @@ module Codeowners
|
|
87
88
|
false
|
88
89
|
end
|
89
90
|
|
91
|
+
def whitelist?
|
92
|
+
whitelist.exist?
|
93
|
+
end
|
94
|
+
|
95
|
+
def whitelist_filename
|
96
|
+
@whitelist_filename ||= CodeOwners.filename(@repo_dir) + '_WHITELIST'
|
97
|
+
end
|
98
|
+
|
99
|
+
def whitelist
|
100
|
+
@whitelist ||= Whitelist.new(whitelist_filename)
|
101
|
+
end
|
102
|
+
|
90
103
|
def codeowners
|
91
104
|
@codeowners ||= CodeOwners.new(
|
92
105
|
FileAsArray.new(CodeOwners.filename(@repo_dir))
|
@@ -108,7 +121,9 @@ module Codeowners
|
|
108
121
|
end
|
109
122
|
|
110
123
|
def unrecognized_line
|
111
|
-
@unrecognized_line ||= codeowners.select
|
124
|
+
@unrecognized_line ||= codeowners.select do |line|
|
125
|
+
line.is_a?(Codeowners::Checker::Group::UnrecognizedLine)
|
126
|
+
end.reject(&whitelist)
|
112
127
|
end
|
113
128
|
|
114
129
|
private
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathspec'
|
4
|
+
|
5
|
+
module Codeowners
|
6
|
+
class Checker
|
7
|
+
# Manage CODEOWNERS_WHITELIST file reading
|
8
|
+
class Whitelist
|
9
|
+
def initialize(filename)
|
10
|
+
@filename = filename
|
11
|
+
end
|
12
|
+
|
13
|
+
def exist?
|
14
|
+
File.exist?(@filename)
|
15
|
+
end
|
16
|
+
|
17
|
+
def whitelisted?(filename)
|
18
|
+
pathspec.match(filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_proc
|
22
|
+
proc { |item| whitelisted?(item) }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def pathspec
|
28
|
+
@pathspec = if File.exist?(@filename)
|
29
|
+
PathSpec.from_filename(@filename)
|
30
|
+
else
|
31
|
+
PathSpec.new([])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/codeowners/cli/main.rb
CHANGED
@@ -24,6 +24,9 @@ module Codeowners
|
|
24
24
|
# for pre-commit: --from HEAD --to index
|
25
25
|
def check(repo = '.')
|
26
26
|
checker = create_checker(repo)
|
27
|
+
Warner.warn("No whitelist found at #{checker.whitelist_filename}") unless
|
28
|
+
checker.whitelist?
|
29
|
+
|
27
30
|
if checker.consistent?
|
28
31
|
Reporter.print '✅ File is consistent'
|
29
32
|
exit 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeowners-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jônatas Davi Paganini
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-04-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fuzzy_match
|
@@ -252,6 +252,7 @@ files:
|
|
252
252
|
- lib/codeowners/checker/owner.rb
|
253
253
|
- lib/codeowners/checker/owners_list.rb
|
254
254
|
- lib/codeowners/checker/version.rb
|
255
|
+
- lib/codeowners/checker/whitelist.rb
|
255
256
|
- lib/codeowners/cli/base.rb
|
256
257
|
- lib/codeowners/cli/config.rb
|
257
258
|
- lib/codeowners/cli/filter.rb
|