@@ -93,23 +93,25 @@ def __init__(
9393 self ._review_graph = None
9494 self ._ask_graph = None
9595 self .metisignore_file = kwargs .get ("metisignore_file" ) or ".metisignore"
96+ self .review_code_include_paths = kwargs .get ("review_code_include_paths" , [])
97+ self .review_code_exclude_paths = kwargs .get ("review_code_exclude_paths" , [])
9698
97- def load_metisignore (self ):
99+ def load_metisignore (self ) -> pathspec . GitIgnoreSpec | None :
98100 """
99- Load metisignore file and return a PathSpec matcher.
101+ Load metisignore file and return a GitIgnoreSpec matcher.
100102
101103 Args:
102104 metisignore: Path to a file that have the ignore regex ( use the .gitignore syntax )
103105
104106 Returns:
105- pathspec.PathSpec object or None if file doesn't exist
107+ pathspec.GitIgnoreSpec object or None if file doesn't exist
106108 """
107109 try :
108110 if not self .metisignore_file :
109111 logger .info ("No MetisIgnore file provided" )
110112 return None
111113 with open (self .metisignore_file , "r" ) as f :
112- spec = pathspec .PathSpec .from_lines ("gitwildmatch" , f )
114+ spec = pathspec .GitIgnoreSpec .from_lines (f )
113115 logger .info (f"MetisIgnore file loaded: { self .metisignore_file } " )
114116 return spec
115117 except FileNotFoundError :
@@ -340,19 +342,35 @@ def review_file(self, file_path):
340342 def get_code_files (self ):
341343 """
342344 Return a list of file names in the self.codebase_path folder.
343- Evaulate the path with metisignore file if requested
345+ Evaluate the path with metisignore file, include/exclude paths if requested
344346 """
345347 base_path = os .path .abspath (self .codebase_path )
346348 metisignore_spec = self .load_metisignore ()
349+ include_spec = None
350+ if self .review_code_include_paths :
351+ include_spec = pathspec .GitIgnoreSpec .from_lines (
352+ self .review_code_include_paths
353+ )
354+ exclude_spec = None
355+ if self .review_code_exclude_paths :
356+ exclude_spec = pathspec .GitIgnoreSpec .from_lines (
357+ self .review_code_exclude_paths
358+ )
347359 file_list = []
348360 for root , _ , files in os .walk (base_path ):
349361 for file in files :
362+ full_path = os .path .join (root , file )
350363 ext = os .path .splitext (file )[1 ].lower ()
351- if ext in self .code_exts and (
352- not metisignore_spec
353- or not metisignore_spec .match_file (os .path .join (root , file ))
354- ):
355- file_list .append (os .path .join (root , file ))
364+ if ext not in self .code_exts :
365+ continue
366+ rel_path = os .path .relpath (full_path , base_path )
367+ if metisignore_spec and metisignore_spec .match_file (rel_path ):
368+ continue
369+ if include_spec and not include_spec .match_file (rel_path ):
370+ continue
371+ if exclude_spec and exclude_spec .match_file (rel_path ):
372+ continue
373+ file_list .append (full_path )
356374 return file_list
357375
358376 def review_code (self ):
0 commit comments