Skip to content

Commit ce31f6a

Browse files
author
Alex Evanczuk
authored
Tidy up references to code_ownership configuration in test (#51)
* Tidy up test references to config/code_ownership.yml * Ignore unowned globs earlier * bump version * small nit
1 parent 5b5fb1c commit ce31f6a

16 files changed

+41
-78
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code_ownership (1.32.5)
4+
code_ownership (1.32.6)
55
code_teams (~> 1.0)
66
packs
77
sorbet-runtime

code_ownership.gemspec

Lines changed: 1 addition & 1 deletion
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.5'
3+
spec.version = '1.32.6'
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def self.path_from_klass(klass)
7676
sig { returns(T::Array[String]) }
7777
def self.tracked_files
7878
@tracked_files ||= T.let(@tracked_files, T.nilable(T::Array[String]))
79-
@tracked_files ||= Dir.glob(configuration.owned_globs)
79+
@tracked_files ||= Dir.glob(configuration.owned_globs) - Dir.glob(configuration.unowned_globs)
8080
end
8181

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

lib/code_ownership/private/validations/files_have_owners.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@ class FilesHaveOwners
1010

1111
sig { override.params(files: T::Array[String], autocorrect: T::Boolean, stage_changes: T::Boolean).returns(T::Array[String]) }
1212
def validation_errors(files:, autocorrect: true, stage_changes: true)
13-
allow_list = Dir.glob(Private.configuration.unowned_globs)
1413
files_by_mapper = Private.glob_cache.files_by_mapper
1514

1615
files_not_mapped_at_all = files.select do |file|
1716
files_by_mapper.fetch(file, []).count == 0
1817
end
1918

20-
files_without_owners = files_not_mapped_at_all - allow_list
21-
2219
errors = T.let([], T::Array[String])
2320

24-
if files_without_owners.any?
21+
if files_not_mapped_at_all.any?
2522
errors << <<~MSG
2623
Some files are missing ownership:
2724
28-
#{files_without_owners.map { |file| "- #{file}" }.join("\n")}
25+
#{files_not_mapped_at_all.map { |file| "- #{file}" }.join("\n")}
2926
MSG
3027
end
3128

spec/lib/code_ownership/cli_spec.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
let(:argv) { ['validate'] }
66

77
before do
8-
write_file('config/code_ownership.yml', <<~YML)
9-
owned_globs:
10-
- 'app/**/*.rb'
11-
YML
12-
8+
write_configuration
139
write_file('app/services/my_file.rb')
1410
write_file('frontend/javascripts/my_file.jsx')
1511
end
@@ -19,7 +15,7 @@
1915
expect(CodeOwnership).to receive(:validate!) do |args| # rubocop:disable RSpec/MessageSpies
2016
expect(args[:autocorrect]).to eq true
2117
expect(args[:stage_changes]).to eq true
22-
expect(args[:files]).to match_array(['app/services/my_file.rb'])
18+
expect(args[:files]).to match_array(["app/services/my_file.rb", "frontend/javascripts/my_file.jsx"])
2319
end
2420
subject
2521
end
@@ -29,10 +25,7 @@
2925

3026
describe 'for_file' do
3127
before do
32-
write_file('config/code_ownership.yml', <<~YML)
33-
owned_globs:
34-
- 'app/**/*.rb'
35-
YML
28+
write_configuration
3629

3730
write_file('app/services/my_file.rb')
3831
write_file('config/teams/my_team.yml', <<~YML)

spec/lib/code_ownership/private/extension_loader_spec.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ module CodeOwnership
44
let(:codeowners_validation) { Private::Validations::GithubCodeownersUpToDate }
55

66
before do
7-
write_file('config/code_ownership.yml', <<~YML)
8-
owned_globs:
9-
- app/**/*.rb
10-
require:
11-
- ./lib/my_extension.rb
12-
YML
7+
write_configuration('require' => ['./lib/my_extension.rb'])
138

149
write_file('config/teams/bar.yml', <<~CONTENTS)
1510
name: Bar
@@ -31,7 +26,7 @@ class MyExtension
3126
returns(T::Hash[String, T.nilable(::CodeTeams::Team)])
3227
end
3328
def map_files_to_owners(files) # rubocop:disable Lint/UnusedMethodArgument
34-
files.map{|f| [f, CodeTeams.all.last]}.to_h
29+
files.select{|f| Pathname.new(f).extname == '.rb'}.map{|f| [f, CodeTeams.all.last]}.to_h
3530
end
3631
3732
sig do
@@ -46,7 +41,7 @@ def map_file_to_owner(file)
4641
override.returns(T::Hash[String, T.nilable(::CodeTeams::Team)])
4742
end
4843
def codeowners_lines_to_owners
49-
Dir.glob('**/*.*').map{|f| [f, CodeTeams.all.last]}.to_h
44+
Dir.glob('**/*.rb').map{|f| [f, CodeTeams.all.last]}.to_h
5045
end
5146
5247
sig { override.returns(String) }
@@ -105,8 +100,6 @@ def bust_caches!
105100
106101
# My special extension
107102
/app/services/my_ownable_file.rb @org/my-team
108-
/config/code_ownership.yml @org/my-team
109-
/config/teams/bar.yml @org/my-team
110103
/lib/my_extension.rb @org/my-team
111104
EXPECTED
112105
end

spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module CodeOwnership
22
RSpec.describe Private::OwnershipMappers::FileAnnotations do
33
describe '.for_team' do
44
before do
5-
create_configuration
5+
write_configuration
66
write_file('config/teams/bar.yml', <<~CONTENTS)
77
name: Bar
88
CONTENTS
@@ -36,7 +36,7 @@ module CodeOwnership
3636
describe '.for_file' do
3737
context 'ruby owned file' do
3838
before do
39-
create_configuration
39+
write_configuration
4040
write_file('config/teams/bar.yml', <<~CONTENTS)
4141
name: Bar
4242
CONTENTS
@@ -53,7 +53,7 @@ module CodeOwnership
5353

5454
context 'javascript owned file' do
5555
before do
56-
create_configuration
56+
write_configuration
5757
write_file('config/teams/bar.yml', <<~CONTENTS)
5858
name: Bar
5959
CONTENTS
@@ -80,7 +80,7 @@ module CodeOwnership
8080
write_file('config/teams/foo.yml', <<~CONTENTS)
8181
name: Foo
8282
CONTENTS
83-
create_minimal_configuration
83+
write_configuration
8484
end
8585

8686
context 'ruby file has no annotation' do

spec/lib/code_ownership/private/ownership_mappers/js_package_ownership_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module CodeOwnership
33
describe 'CodeOwnership.validate!' do
44
context 'application has invalid JSON in package' do
55
before do
6-
write_file('config/code_ownership.yml', {}.to_yaml)
6+
write_configuration
77

88
write_file('frontend/javascripts/my_package/package.json', <<~CONTENTS)
99
{ syntax error!!!
@@ -27,7 +27,7 @@ module CodeOwnership
2727

2828
describe 'CodeOwnershp.for_file' do
2929
before do
30-
create_configuration
30+
write_configuration
3131

3232
write_file('frontend/javascripts/packages/my_other_package/package.json', <<~CONTENTS)
3333
{

spec/lib/code_ownership/private/ownership_mappers/package_ownership_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module CodeOwnership
22
RSpec.describe Private::OwnershipMappers::PackageOwnership do
33
before do
4-
create_configuration
4+
write_configuration
55
write_file('config/teams/bar.yml', <<~CONTENTS)
66
name: Bar
77
CONTENTS

spec/lib/code_ownership/private/ownership_mappers/team_globs_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module CodeOwnership
22
RSpec.describe Private::OwnershipMappers::TeamGlobs do
3-
before { create_configuration }
3+
before { write_configuration }
44

55
describe 'CodeOwnership.for_file' do
66
before do
@@ -27,10 +27,7 @@ module CodeOwnership
2727
describe 'CodeOwnership.validate!' do
2828
context 'two teams own the same exact glob' do
2929
before do
30-
write_file('config/code_ownership.yml', <<~YML)
31-
owned_globs:
32-
- '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}'
33-
YML
30+
write_configuration
3431

3532
write_file('packs/my_pack/owned_file.rb')
3633
write_file('frontend/javascripts/blah/my_file.rb')

0 commit comments

Comments
 (0)