1- use std:: { collections:: { HashMap , HashSet } , fs, path:: Path } ;
1+ use std:: {
2+ collections:: { HashMap , HashSet } ,
3+ fs,
4+ path:: Path ,
5+ } ;
26
37use fast_glob:: glob_match;
48use glob:: glob;
@@ -20,10 +24,7 @@ pub fn find_file_owners(project_root: &Path, config: &Config, file_path: &Path)
2024 . unwrap_or ( & absolute_file_path)
2125 . to_path_buf ( ) ;
2226
23- let teams = match load_teams ( project_root, & config. team_file_glob ) {
24- Ok ( t) => t,
25- Err ( e) => return Err ( e) ,
26- } ;
27+ let teams = load_teams ( project_root, & config. team_file_glob ) ?;
2728 let teams_by_name = build_teams_by_name_map ( & teams) ;
2829
2930 let mut sources_by_team: HashMap < String , Vec < Source > > = HashMap :: new ( ) ;
@@ -68,11 +69,7 @@ pub fn find_file_owners(project_root: &Path, config: &Config, file_path: &Path)
6869 }
6970
7071 for team in & teams {
71- let team_rel = team
72- . path
73- . strip_prefix ( project_root)
74- . unwrap_or ( & team. path )
75- . to_path_buf ( ) ;
72+ let team_rel = team. path . strip_prefix ( project_root) . unwrap_or ( & team. path ) . to_path_buf ( ) ;
7673 if team_rel == relative_file_path {
7774 sources_by_team. entry ( team. name . clone ( ) ) . or_default ( ) . push ( Source :: TeamYml ) ;
7875 }
@@ -99,18 +96,8 @@ pub fn find_file_owners(project_root: &Path, config: &Config, file_path: &Path)
9996 // This is simply matching the order of behavior of the original codeowners CLI
10097 if file_owners. len ( ) > 1 {
10198 file_owners. sort_by ( |a, b| {
102- let priority_a = a
103- . sources
104- . iter ( )
105- . map ( |s| source_priority ( s) )
106- . min ( )
107- . unwrap_or ( u8:: MAX ) ;
108- let priority_b = b
109- . sources
110- . iter ( )
111- . map ( |s| source_priority ( s) )
112- . min ( )
113- . unwrap_or ( u8:: MAX ) ;
99+ let priority_a = a. sources . iter ( ) . map ( source_priority) . min ( ) . unwrap_or ( u8:: MAX ) ;
100+ let priority_b = b. sources . iter ( ) . map ( source_priority) . min ( ) . unwrap_or ( u8:: MAX ) ;
114101 priority_a. cmp ( & priority_b) . then_with ( || a. team . name . cmp ( & b. team . name ) )
115102 } ) ;
116103 }
@@ -204,7 +191,9 @@ fn most_specific_directory_owner(
204191 }
205192 }
206193 }
207- if parent == project_root { break ; }
194+ if parent == project_root {
195+ break ;
196+ }
208197 current = parent. clone ( ) ;
209198 }
210199 best
@@ -229,10 +218,10 @@ fn nearest_package_owner(
229218 if let Some ( team) = teams_by_name. get ( & owner) {
230219 let package_path = parent_rel. join ( "package.yml" ) ;
231220 let package_glob = format ! ( "{}/**/**" , rel_str) ;
232- return Some ( ( team . name . clone ( ) , Source :: Package (
233- package_path . to_string_lossy ( ) . to_string ( ) ,
234- package_glob,
235- ) ) ) ;
221+ return Some ( (
222+ team . name . clone ( ) ,
223+ Source :: Package ( package_path . to_string_lossy ( ) . to_string ( ) , package_glob) ,
224+ ) ) ;
236225 }
237226 }
238227 }
@@ -244,16 +233,18 @@ fn nearest_package_owner(
244233 if let Some ( team) = teams_by_name. get ( & owner) {
245234 let package_path = parent_rel. join ( "package.json" ) ;
246235 let package_glob = format ! ( "{}/**/**" , rel_str) ;
247- return Some ( ( team . name . clone ( ) , Source :: Package (
248- package_path . to_string_lossy ( ) . to_string ( ) ,
249- package_glob,
250- ) ) ) ;
236+ return Some ( (
237+ team . name . clone ( ) ,
238+ Source :: Package ( package_path . to_string_lossy ( ) . to_string ( ) , package_glob) ,
239+ ) ) ;
251240 }
252241 }
253242 }
254243 }
255244 }
256- if parent == project_root { break ; }
245+ if parent == project_root {
246+ break ;
247+ }
257248 current = parent;
258249 }
259250 None
@@ -285,18 +276,22 @@ fn read_js_package_owner(path: &Path) -> std::result::Result<String, String> {
285276 . ok_or_else ( || "Missing owner" . to_string ( ) )
286277}
287278
288- fn vendored_gem_owner (
289- relative_file_path : & Path ,
290- config : & Config ,
291- teams : & [ Team ] ,
292- ) -> Option < ( String , Source ) > {
279+ fn vendored_gem_owner ( relative_file_path : & Path , config : & Config , teams : & [ Team ] ) -> Option < ( String , Source ) > {
293280 use std:: path:: Component ;
294281 let mut comps = relative_file_path. components ( ) ;
295282 let first = comps. next ( ) ?;
296283 let second = comps. next ( ) ?;
297- let first_str = match first { Component :: Normal ( s) => s. to_string_lossy ( ) , _ => return None } ;
298- if first_str != config. vendored_gems_path { return None ; }
299- let gem_name = match second { Component :: Normal ( s) => s. to_string_lossy ( ) . to_string ( ) , _ => return None } ;
284+ let first_str = match first {
285+ Component :: Normal ( s) => s. to_string_lossy ( ) ,
286+ _ => return None ,
287+ } ;
288+ if first_str != config. vendored_gems_path {
289+ return None ;
290+ }
291+ let gem_name = match second {
292+ Component :: Normal ( s) => s. to_string_lossy ( ) . to_string ( ) ,
293+ _ => return None ,
294+ } ;
300295 for team in teams {
301296 if team. owned_gems . iter ( ) . any ( |g| g == & gem_name) {
302297 return Some ( ( team. name . clone ( ) , Source :: TeamGem ) ) ;
@@ -316,5 +311,3 @@ fn source_priority(source: &Source) -> u8 {
316311 Source :: TeamYml => 5 ,
317312 }
318313}
319-
320-
0 commit comments