@@ -4,7 +4,6 @@ use crate::{
44} ;
55use fast_glob:: glob_match;
66use memoize:: memoize;
7- use rayon:: prelude:: * ;
87use regex:: Regex ;
98use std:: {
109 collections:: HashMap ,
@@ -23,57 +22,33 @@ pub struct Parser {
2322}
2423
2524impl Parser {
26- pub fn teams_from_files_paths ( & self , file_paths : & [ PathBuf ] ) -> Result < HashMap < String , Option < Team > > , Box < dyn Error > > {
27- let file_inputs: Vec < ( String , String ) > = file_paths
28- . iter ( )
29- . map ( |path| {
30- let file_path_str = path
31- . to_str ( )
32- . ok_or ( IoError :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid file path" ) ) ?;
33- let original = file_path_str. to_string ( ) ;
34- let prefixed = if file_path_str. starts_with ( '/' ) {
35- original. clone ( )
36- } else {
37- format ! ( "/{}" , file_path_str)
38- } ;
39- Ok ( ( original, prefixed) )
40- } )
41- . collect :: < Result < Vec < _ > , IoError > > ( ) ?;
42-
43- if file_inputs. is_empty ( ) {
44- return Ok ( HashMap :: new ( ) ) ;
45- }
46-
47- let codeowners_entries: Vec < ( String , String ) > =
48- build_codeowners_lines_in_priority ( self . codeowners_file_path . to_string_lossy ( ) . into_owned ( ) )
49- . iter ( )
50- . map ( |line| {
51- line. split_once ( ' ' )
52- . map ( |( glob, team_name) | ( glob. to_string ( ) , team_name. to_string ( ) ) )
53- . ok_or_else ( || IoError :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid line" ) )
54- } )
55- . collect :: < Result < _ , IoError > > ( )
56- . map_err ( |e| Box :: new ( e) as Box < dyn Error > ) ?;
57-
58- let teams_by_name = teams_by_github_team_name ( self . absolute_team_files_globs ( ) ) ;
59-
60- let result: HashMap < String , Option < Team > > = file_inputs
61- . par_iter ( )
62- . map ( |( key, prefixed) | {
63- let team = codeowners_entries
64- . iter ( )
65- . find ( |( glob, _) | glob_match ( glob, prefixed) )
66- . and_then ( |( _, team_name) | teams_by_name. get ( team_name) . cloned ( ) ) ;
67- ( key. clone ( ) , team)
68- } )
69- . collect ( ) ;
70-
71- Ok ( result)
25+ pub fn teams_from_files_paths ( & self , file_paths : & [ PathBuf ] ) -> Result < HashMap < String , Team > , Box < dyn Error > > {
26+ todo ! ( )
7227 }
73-
28+
7429 pub fn team_from_file_path ( & self , file_path : & Path ) -> Result < Option < Team > , Box < dyn Error > > {
75- let teams = self . teams_from_files_paths ( & [ file_path. to_path_buf ( ) ] ) ?;
76- Ok ( teams. get ( file_path. to_string_lossy ( ) . into_owned ( ) . as_str ( ) ) . cloned ( ) . flatten ( ) )
30+ let file_path_str = file_path
31+ . to_str ( )
32+ . ok_or ( IoError :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid file path" ) ) ?;
33+ let slash_prefixed = if file_path_str. starts_with ( "/" ) {
34+ file_path_str. to_string ( )
35+ } else {
36+ format ! ( "/{}" , file_path_str)
37+ } ;
38+
39+ let codeowners_lines_in_priorty = build_codeowners_lines_in_priority ( self . codeowners_file_path . to_string_lossy ( ) . into_owned ( ) ) ;
40+ for line in codeowners_lines_in_priorty {
41+ let ( glob, team_name) = line
42+ . split_once ( ' ' )
43+ . ok_or ( IoError :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid line" ) ) ?;
44+ if glob_match ( glob, & slash_prefixed) {
45+ let tbn = teams_by_github_team_name ( self . absolute_team_files_globs ( ) ) ;
46+ let team: Option < Team > = tbn. get ( team_name. to_string ( ) . as_str ( ) ) . cloned ( ) ;
47+ return Ok ( team) ;
48+ }
49+ }
50+
51+ Ok ( None )
7752 }
7853
7954 fn absolute_team_files_globs ( & self ) -> Vec < String > {
0 commit comments