Skip to content

Commit

Permalink
commenting on the need for adding a file without a glob match
Browse files Browse the repository at this point in the history
Co-authored-by: Joey Schoblaska <[email protected]>
  • Loading branch information
perryqh and schoblaska committed Feb 16, 2024
1 parent d3f4e25 commit db54310
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/code_ownership/private/owner_assigner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/code_ownership/private/owner_assigner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit db54310

Please sign in to comment.