Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/code_ownership/private/team_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ def for_file(file_path, allow_raise: false)

sig { params(files: T::Array[String], allow_raise: T::Boolean).returns(T::Hash[String, T.nilable(CodeTeams::Team)]) }
def teams_for_files(files, allow_raise: false)
::RustCodeOwners.teams_for_files(files).each_with_object({}) do |path_team, hash|
result = {}

# Collect cached results and identify non-cached files
not_cached_files = []
files.each do |file_path|
if FilePathTeamCache.cached?(file_path)
result[file_path] = FilePathTeamCache.get(file_path)
else
not_cached_files << file_path
end
end

return result if not_cached_files.empty?

# Process non-cached files
::RustCodeOwners.teams_for_files(not_cached_files).each do |path_team|
file_path, team = path_team
found_team = team ? find_team!(team[:team_name], allow_raise: allow_raise) : nil
FilePathTeamCache.set(file_path, found_team)
hash[file_path] = found_team
result[file_path] = found_team
end

result
end

sig { params(klass: T.nilable(T.any(T::Class[T.anything], Module))).returns(T.nilable(::CodeTeams::Team)) }
Expand Down
2 changes: 1 addition & 1 deletion lib/code_ownership/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CodeOwnership
VERSION = '2.0.0-3'
VERSION = '2.0.0-4'
end
9 changes: 9 additions & 0 deletions spec/lib/code_ownership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@
it 'returns the correct team' do
expect(subject).to eq CodeTeams.find('Bar')
end

context 'when ownership is cached' do
it 'returns the correct team' do
expect(subject).to eq CodeTeams.find('Bar')
allow(RustCodeOwners).to receive(:teams_for_files)
expect(CodeOwnership.for_file(file_path)).to eq CodeTeams.find('Bar')
expect(RustCodeOwners).not_to have_received(:teams_for_files)
end
end
end

context 'when ownership is found but team is not found' do
Expand Down