Skip to content

Commit 727b083

Browse files
author
Alex Evanczuk
authored
Fix issue where codeowners file references deleted file (#61)
* add failing test * Fix test * Bump version
1 parent 7cd5039 commit 727b083

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code_ownership (1.32.13)
4+
code_ownership (1.32.14)
55
code_teams (~> 1.0)
66
packs
77
sorbet-runtime

code_ownership.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'code_ownership'
3-
spec.version = '1.32.13'
3+
spec.version = '1.32.14'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66
spec.summary = 'A gem to help engineering teams declare ownership of code'

lib/code_ownership/private.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def self.file_tracked?(file)
9696
File.fnmatch?(unowned_glob, file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
9797
end
9898

99-
in_owned_globs && !in_unowned_globs
99+
in_owned_globs && !in_unowned_globs && File.exist?(file)
100100
end
101101

102102
sig { params(team_name: String, location_of_reference: String).returns(CodeTeams::Team) }

spec/lib/code_ownership/private/validations/github_codeowners_up_to_date_spec.rb

+51
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,57 @@ module CodeOwnership
526526
end
527527
end
528528
end
529+
530+
context 'in an application with a CODEOWNERS file that has a reference to a file that no longer exists' do
531+
before do
532+
write_configuration
533+
534+
write_file('packs/my_pack/owned_file.rb', <<~CONTENTS)
535+
# @team Bar
536+
CONTENTS
537+
538+
write_file('config/teams/bar.yml', <<~CONTENTS)
539+
name: Bar
540+
github:
541+
team: '@MyOrg/bar-team'
542+
CONTENTS
543+
end
544+
545+
it 'prints out the diff' do
546+
FileUtils.mkdir('.github')
547+
codeowners_path.write <<~CODEOWNERS
548+
# STOP! - DO NOT EDIT THIS FILE MANUALLY
549+
# This file was automatically generated by "bin/codeownership validate".
550+
#
551+
# CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub
552+
# teams. This is useful when developers create Pull Requests since the
553+
# code/file owner is notified. Reference GitHub docs for more details:
554+
# https://help.github.com/en/articles/about-code-owners
555+
556+
557+
# Annotations at the top of file
558+
/packs/my_pack/owned_file.rb @MyOrg/bar-team
559+
/packs/my_pack/deleted_file.rb @MyOrg/bar-team
560+
CODEOWNERS
561+
562+
expect_any_instance_of(codeowners_validation).to_not receive(:`) # rubocop:disable RSpec/AnyInstance
563+
expect { CodeOwnership.validate!(autocorrect: false) }.to raise_error do |e|
564+
expect(e).to be_a CodeOwnership::InvalidCodeOwnershipConfigurationError
565+
expect(e.message).to eq <<~EXPECTED.chomp
566+
CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
567+
568+
CODEOWNERS should contain the following lines, but does not:
569+
- "# Team YML ownership"
570+
- "/config/teams/bar.yml @MyOrg/bar-team"
571+
572+
CODEOWNERS should not contain the following lines, but it does:
573+
- "/packs/my_pack/deleted_file.rb @MyOrg/bar-team"
574+
575+
See https://github.com/rubyatscale/code_ownership#README.md for more details
576+
EXPECTED
577+
end
578+
end
579+
end
529580
end
530581

531582
context 'code_ownership.yml has skip_codeowners_validation set' do

0 commit comments

Comments
 (0)