Skip to content

Commit 40afe76

Browse files
authored
looks like .codeowner files can override each other (#97)
1 parent 1921eed commit 40afe76

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.2.2

lib/code_ownership.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def for_file(file)
3939

4040
Mapper.all.each do |mapper|
4141
owner = mapper.map_file_to_owner(file)
42-
break if owner
42+
break if owner # TODO: what if there are multiple owners? Should we respond with an error instead of the first match?
4343
end
4444

4545
@for_file[file] = owner

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ module CodeOwnership
9090
end
9191
end
9292
end
93+
94+
context 'with mutliple directory ownership files' do
95+
before do
96+
write_configuration
97+
98+
write_file('config/teams/bar.yml', <<~CONTENTS)
99+
name: Bar
100+
CONTENTS
101+
102+
write_file('config/teams/foo.yml', <<~CONTENTS)
103+
name: Foo
104+
CONTENTS
105+
106+
write_file('app/services/exciting/some_other_file.rb', <<~YML)
107+
class Exciting::SomeOtherFile; end
108+
YML
109+
110+
write_file('app/services/exciting/.codeowner', <<~YML)
111+
Bar
112+
YML
113+
114+
write_file('app/services/.codeowner', <<~YML)
115+
Foo
116+
YML
117+
end
118+
119+
it 'allows multiple .codeowner ancestor files' do
120+
expect(CodeOwnership.for_file('app/services/exciting/some_other_file.rb').name).to eq 'Bar'
121+
expect { CodeOwnership.validate! }.to_not raise_error
122+
end
123+
end
93124
end
94125
end
95126
end

0 commit comments

Comments
 (0)