Skip to content

Commit 5b4c20d

Browse files
ashleywillardmartinemde
authored andcommitted
update the way we glob team files
1 parent 39bed6a commit 5b4c20d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

lib/code_ownership/private/owner_assigner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def self.assign_owners(globs_to_owning_team_map)
1212
# addresses the case where a directory name includes regex characters
1313
# such as `app/services/[test]/some_other_file.ts`
1414
mapping[glob] = owner if File.exist?(glob)
15-
Dir.glob(glob).each do |file|
15+
Dir.glob(glob) do |file|
1616
mapping[file] ||= owner
1717
end
1818
end

lib/code_ownership/private/ownership_mappers/team_globs.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@ def map_files_to_owners
2020
return @@map_files_to_owners if @@map_files_to_owners&.keys && @@map_files_to_owners.keys.count.positive?
2121

2222
@@map_files_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
23-
TeamPlugins::Ownership.for(team).owned_globs.each do |glob|
24-
Dir.glob(glob).each do |filename|
25-
map[filename] = team
26-
end
27-
end
23+
code_team = TeamPlugins::Ownership.for(team)
2824

29-
# Remove anything that is unowned
30-
TeamPlugins::Ownership.for(team).unowned_globs.each do |glob|
31-
Dir.glob(glob).each do |filename|
32-
map.delete(filename)
33-
end
25+
(Dir.glob(code_team.owned_globs) - Dir.glob(code_team.unowned_globs)).each do |filename|
26+
map[filename] = team
3427
end
3528
end
3629
end
@@ -64,14 +57,15 @@ def find_overlapping_globs
6457
mapped_files = T.let({}, T::Hash[String, T::Array[MappingContext]])
6558
CodeTeams.all.each_with_object({}) do |team, _map|
6659
TeamPlugins::Ownership.for(team).owned_globs.each do |glob|
67-
Dir.glob(glob).each do |filename|
60+
Dir.glob(glob) do |filename|
6861
mapped_files[filename] ||= []
6962
T.must(mapped_files[filename]) << MappingContext.new(glob: glob, team: team)
7063
end
7164
end
65+
7266
# Remove anything that is unowned
7367
TeamPlugins::Ownership.for(team).unowned_globs.each do |glob|
74-
Dir.glob(glob).each do |filename|
68+
Dir.glob(glob) do |filename|
7569
mapped_files.reject! { |key, value| key == filename && value.any? { |context| context.team == team } }
7670
end
7771
end

0 commit comments

Comments
 (0)