Skip to content

Commit

Permalink
Fix bug associated with validate when input file is unowned (#60)
Browse files Browse the repository at this point in the history
* Fix bug associated with validate when input file is unowned

* bump version
  • Loading branch information
Alex Evanczuk authored Apr 15, 2023
1 parent a0cb927 commit 7cd5039
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
code_ownership (1.32.12)
code_ownership (1.32.13)
code_teams (~> 1.0)
packs
sorbet-runtime
Expand Down
2 changes: 1 addition & 1 deletion code_ownership.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'code_ownership'
spec.version = '1.32.12'
spec.version = '1.32.13'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'A gem to help engineering teams declare ownership of code'
Expand Down
2 changes: 1 addition & 1 deletion lib/code_ownership/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def self.file_tracked?(file)
File.fnmatch?(owned_glob, file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
end

in_unowned_globs = configuration.unowned_globs.all? do |unowned_glob|
in_unowned_globs = configuration.unowned_globs.any? do |unowned_glob|
File.fnmatch?(unowned_glob, file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
end

Expand Down
34 changes: 34 additions & 0 deletions spec/lib/code_ownership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@
end
end
end

context 'file is unowned' do
before do
write_file('config/teams/bar.yml', <<~CONTENTS)
name: Bar
CONTENTS

write_configuration

write_file('app/services/autogenerated_code/some_unowned_file.rb', '')
end

it 'has no validation errors' do
expect { CodeOwnership.validate!(files: ['app/services/autogenerated_code/some_unowned_file.rb']) }.to raise_error do |e|
expect(e.message).to eq <<~MSG.chomp
Some files are missing ownership:
- app/services/autogenerated_code/some_unowned_file.rb
See https://github.com/rubyatscale/code_ownership#README.md for more details
MSG
end
end

context 'ignored file passed in that is ignored' do
before do
write_configuration('unowned_globs' => ['app/services/autogenerated_code/**/**', 'vendor/bundle/**/**'])
end

it 'has no validation errors' do
expect { CodeOwnership.validate!(files: ['app/services/autogenerated_code/some_unowned_file.rb']) }.to_not raise_error
end
end
end
end

# See tests for individual ownership_mappers to understand behavior for each mapper
Expand Down

0 comments on commit 7cd5039

Please sign in to comment.