@@ -146,7 +146,7 @@ def load_config(self) -> List[Dict[str, str]]:
146146
147147 return resolved_rules
148148
149- def scan_file (file_path : str , compiled_rules : List [Dict [str , re .Pattern ]]) -> List [Dict [str , str ]]:
149+ def scan_file (file_path : str , compiled_rules : List [Dict [str , re .Pattern ]]) -> List [Dict [str , Any ]]:
150150 """
151151 Scan a single file for matching patterns.
152152
@@ -239,23 +239,29 @@ def _safe_int(value: Any, default: int = 0) -> int:
239239 return default
240240
241241
242- def format_for_raw_csv (match : Dict [str , str ]) -> Dict [str , str ]:
242+ def format_for_raw_csv (match : Dict [str , Any ]) -> Dict [str , Any ]:
243243 """Prepares a full raw dataset (n + x columns) with clean text values."""
244+ file_name = match .get ("file_name" )
245+ if not file_name and match .get ("file_path" ):
246+ file_name = os .path .basename (match .get ("file_path" ))
244247 return {
248+ "file_name" : file_name or "" ,
245249 "file_path" : match .get ("file_path" , "" ),
246250 "package_name" : match .get ("package_name" , "" ),
247251 "rule_name" : match .get ("rule_name" , "" ),
248252 "line_number" : _safe_int (match .get ("line_number" )),
249253 "matched_string" : match .get ("matched_string" , "" ),
250- "context_line" : _truncate_context (match .get ("context_line" , "" ), match .get ("matched_string" , "" ))
254+ "context_line" : _truncate_context (match .get ("context_line" , "" ), match .get ("matched_string" , "" )),
255+ "dependency" : match .get ("dependency" , "" ),
256+ "version" : match .get ("version" , "" )
251257 }
252258
253259
254260def format_for_spreadsheet (
255- match : Dict [str , str ],
261+ match : Dict [str , Any ],
256262 github_repo : str = None ,
257263 branch : str = "main"
258- ) -> Dict [str , str ]:
264+ ) -> Dict [str , Any ]:
259265 """Builds on top of raw CSV but applies Sheets-specific formulas."""
260266 formatted = format_for_raw_csv (match )
261267
@@ -270,7 +276,7 @@ def format_for_spreadsheet(
270276 return formatted
271277
272278
273- def format_for_console (match : Dict [str , str ]) -> str :
279+ def format_for_console (match : Dict [str , Any ]) -> str :
274280 """Prepares a slim, readable string representation (n columns) for stdout/logs."""
275281 file_path = match .get ("file_path" , "" )
276282 line_number = match .get ("line_number" , "" )
@@ -280,7 +286,7 @@ def format_for_console(match: Dict[str, str]) -> str:
280286
281287
282288
283- def get_match_counts (matches : List [Dict [str , str ]]) -> Tuple [Dict [str , int ], Dict [str , int ]]:
289+ def get_match_counts (matches : List [Dict [str , Any ]]) -> Tuple [Dict [str , int ], Dict [str , int ]]:
284290 """
285291 Aggregate matches by rule and by package.
286292 """
@@ -333,7 +339,7 @@ def load_ignore_file(file_path: str) -> List[str]:
333339
334340def write_csv_report (
335341 output_path : str ,
336- matches : List [Dict [str , str ]]
342+ matches : List [Dict [str , Any ]]
337343) -> None :
338344 """
339345 Write the collected matches to a CSV file.
@@ -342,7 +348,7 @@ def write_csv_report(
342348 output_path: Path to the output CSV file.
343349 matches: A list of dictionaries containing match details.
344350 """
345- fieldnames = ["file_path" , "package_name" , "rule_name" , "line_number" , "matched_string" , "context_line" ]
351+ fieldnames = ["file_name" , " file_path" , "package_name" , "rule_name" , "dependency" , "version " , "line_number" , "matched_string" , "context_line" ]
346352
347353 try :
348354 with open (output_path , 'w' , encoding = 'utf-8' , newline = '' ) as f :
@@ -360,7 +366,7 @@ def write_csv_report(
360366 print (f"Error writing CSV report: { e } " , file = sys .stderr )
361367
362368
363- def upload_to_drive (csv_path : str , matches : List [Dict [str , str ]], github_repo : str = None , branch : str = "main" ) -> str :
369+ def upload_to_drive (csv_path : str , matches : List [Dict [str , Any ]], github_repo : str = None , branch : str = "main" ) -> str :
364370 """
365371 Upload matches to a Google Sheet in Drive.
366372 """
@@ -391,13 +397,16 @@ def upload_to_drive(csv_path: str, matches: List[Dict[str, str]], github_repo: s
391397 spreadsheet_id = spreadsheet .get ('spreadsheetId' )
392398
393399 # Prepare data
394- values = [["file_path" , "package_name" , "rule_name" , "line_number" , "matched_string" , "context_line" ]]
400+ values = [["file_name" , " file_path" , "package_name" , "rule_name" , "dependency" , "version " , "line_number" , "matched_string" , "context_line" ]]
395401 for m in matches :
396402 formatted_m = format_for_spreadsheet (m , github_repo = github_repo , branch = branch )
397403 values .append ([
404+ formatted_m .get ("file_name" , "" ),
398405 formatted_m .get ("file_path" , "" ),
399406 formatted_m .get ("package_name" , "" ),
400407 formatted_m .get ("rule_name" , "" ),
408+ formatted_m .get ("dependency" , "" ),
409+ formatted_m .get ("version" , "" ),
401410 str (formatted_m .get ("line_number" , "" )),
402411 formatted_m .get ("matched_string" , "" ),
403412 formatted_m .get ("context_line" , "" )
@@ -460,7 +469,7 @@ def scan_repository(
460469 target_packages : List [str ] = None ,
461470 ignore_dirs : List [str ] = None ,
462471 version_string : str = None
463- ) -> List [Dict [str , str ]]:
472+ ) -> List [Dict [str , Any ]]:
464473 """
465474 Scans the repository directory tree applying resolved regex patterns to files.
466475
@@ -510,7 +519,6 @@ def scan_repository(
510519 files = [f for f in files if f .lower () not in ignore_lower ]
511520
512521 rel_root = os .path .relpath (root , root_path )
513- parts = rel_root .split (os .sep )
514522
515523 # Layout-agnostic generic subdirectory filtering
516524 if target_packages :
@@ -559,6 +567,7 @@ def scan_repository(
559567 display_path = rel_file_path
560568
561569 for m in matches :
570+ m ["file_name" ] = file
562571 m ["file_path" ] = display_path
563572 m ["repo_path" ] = rel_file_path
564573 m ["package_name" ] = package_name
@@ -663,7 +672,7 @@ def main():
663672
664673 print (f"Starting scan for dependency: { args .dependency } version: { args .version } " )
665674 print (f"Root path: { args .path } " )
666- print (f "Targets to scan:" )
675+ print ("Targets to scan:" )
667676 if target_packages :
668677 for pkg in target_packages :
669678 print (f" - { os .path .join (args .path , pkg )} " )
0 commit comments