@@ -6,13 +6,7 @@ use fast_glob::glob_match;
66use memoize:: memoize;
77use rayon:: prelude:: * ;
88use regex:: Regex ;
9- use std:: {
10- collections:: HashMap ,
11- error:: Error ,
12- fs,
13- io:: Error as IoError ,
14- path:: { Path , PathBuf } ,
15- } ;
9+ use std:: { collections:: HashMap , error:: Error , fs, io:: Error as IoError , path:: PathBuf } ;
1610
1711use super :: file_generator:: compare_lines;
1812
@@ -44,16 +38,7 @@ impl Parser {
4438 return Ok ( HashMap :: new ( ) ) ;
4539 }
4640
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 > ) ?;
41+ let codeowners_entries = parse_codeowners_entries ( self . codeowners_file_path . to_string_lossy ( ) . into_owned ( ) ) ;
5742
5843 let teams_by_name = teams_by_github_team_name ( self . absolute_team_files_globs ( ) ) ;
5944
@@ -71,11 +56,6 @@ impl Parser {
7156 Ok ( result)
7257 }
7358
74- 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 ( ) )
77- }
78-
7959 fn absolute_team_files_globs ( & self ) -> Vec < String > {
8060 self . team_file_globs
8161 . iter ( )
@@ -111,7 +91,6 @@ fn teams_by_github_team_name(team_file_glob: Vec<String>) -> HashMap<String, Tea
11191 teams
11292}
11393
114- #[ memoize]
11594fn build_codeowners_lines_in_priority ( codeowners_file_path : String ) -> Vec < String > {
11695 let codeowners_file = match fs:: read_to_string ( codeowners_file_path) {
11796 Ok ( codeowners_file) => codeowners_file,
@@ -124,6 +103,16 @@ fn build_codeowners_lines_in_priority(codeowners_file_path: String) -> Vec<Strin
124103 stripped_lines_by_priority ( & codeowners_file)
125104}
126105
106+ fn parse_codeowners_entries ( codeowners_file_path : String ) -> Vec < ( String , String ) > {
107+ build_codeowners_lines_in_priority ( codeowners_file_path)
108+ . iter ( )
109+ . filter_map ( |line| {
110+ line. split_once ( ' ' )
111+ . map ( |( glob, team_name) | ( glob. to_string ( ) , team_name. to_string ( ) ) )
112+ } )
113+ . collect ( )
114+ }
115+
127116#[ derive( Debug , Clone , PartialEq , Eq ) ]
128117struct Section {
129118 heading : String ,
0 commit comments