File tree Expand file tree Collapse file tree 4 files changed +21
-3
lines changed
Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,7 @@ def for_file(file)
4747
4848 sig { params ( files : T ::Array [ String ] ) . returns ( T ::Hash [ String , T . nilable ( CodeTeams ::Team ) ] ) }
4949 def team_names_for_files ( files )
50- ::RustCodeOwners . team_names_for_files ( files ) . transform_values do |team |
51- team ? CodeTeams . find ( team [ :team_name ] ) : nil
52- end
50+ Private ::TeamFinder . team_names_for_files ( files )
5351 end
5452
5553 sig { params ( file : String ) . returns ( T . nilable ( T ::Hash [ Symbol , String ] ) ) }
Original file line number Diff line number Diff line change @@ -30,6 +30,16 @@ def for_file(file_path)
3030 FilePathTeamCache . get ( file_path )
3131 end
3232
33+ sig { params ( files : T ::Array [ String ] ) . returns ( T ::Hash [ String , T . nilable ( CodeTeams ::Team ) ] ) }
34+ def team_names_for_files ( files )
35+ ::RustCodeOwners . team_names_for_files ( files ) . each_with_object ( { } ) do |path_team , hash |
36+ file_path , team = path_team
37+ found_team = team ? CodeTeams . find ( team [ :team_name ] ) : nil
38+ FilePathTeamCache . set ( file_path , found_team )
39+ hash [ file_path ] = found_team
40+ end
41+ end
42+
3343 sig { params ( klass : T . nilable ( T . any ( T ::Class [ T . anything ] , Module ) ) ) . returns ( T . nilable ( ::CodeTeams ::Team ) ) }
3444 def for_class ( klass )
3545 file_path = FilePathFinder . path_from_klass ( klass )
Original file line number Diff line number Diff line change 4242 it 'returns the correct team' do
4343 expect ( subject ) . to eq ( { 'packs/my_pack/owned_file.rb' => CodeTeams . find ( 'Bar' ) } )
4444 end
45+
46+ context 'subsequent for_file utilizes cached team' do
47+ let ( :files ) { [ 'packs/my_pack/owned_file.rb' , 'packs/my_pack/owned_file2.rb' ] }
48+ it 'returns the correct team' do
49+ subject # caches paths -> teams
50+ allow ( RustCodeOwners ) . to receive ( :for_file )
51+ expect ( described_class . for_file ( 'packs/my_pack/owned_file.rb' ) ) . to eq ( CodeTeams . find ( 'Bar' ) )
52+ expect ( RustCodeOwners ) . to_not have_received ( :for_file )
53+ end
54+ end
4555 end
4656
4757 context 'when ownership is found but team is not found' do
You can’t perform that action at this time.
0 commit comments