diff --git a/lib/code_ownership/private/owner_assigner.rb b/lib/code_ownership/private/owner_assigner.rb index d6d9807..e6e1665 100644 --- a/lib/code_ownership/private/owner_assigner.rb +++ b/lib/code_ownership/private/owner_assigner.rb @@ -9,6 +9,8 @@ class OwnerAssigner sig { params(globs_to_owning_team_map: GlobsToOwningTeamMap).returns(GlobsToOwningTeamMap) } def self.assign_owners(globs_to_owning_team_map) globs_to_owning_team_map.each_with_object({}) do |(glob, owner), mapping| + # addresses the case where a directory name includes regex characters + # such as `app/services/[test]/some_other_file.ts` mapping[glob] = owner if File.exist?(glob) Dir.glob(glob).each do |file| mapping[file] ||= owner diff --git a/spec/lib/code_ownership/private/owner_assigner_spec.rb b/spec/lib/code_ownership/private/owner_assigner_spec.rb index 52a47f2..657a673 100644 --- a/spec/lib/code_ownership/private/owner_assigner_spec.rb +++ b/spec/lib/code_ownership/private/owner_assigner_spec.rb @@ -46,6 +46,26 @@ module CodeOwnership ) end end + + context 'when * is used in glob pattern' do + before do + write_file('app/models/some_file.rb', <<~YML) + // @team Bar + YML + + write_file('app/models/nested/some_file.rb', <<~YML) + // @team Bar + YML + end + + it 'also matches the glob pattern' do + expect(assign_owners).to eq( + 'app/services/[test]/some_other_file.ts' => team_1, + 'app/services/withoutbracket/file.ts' => team_2, + 'app/models/some_file.rb' => team_2 + ) + end + end end end end