11import collections
2- import json
32import logging
43import pathlib
54import webbrowser
@@ -16,7 +15,7 @@ def get_global(global_results, _global):
1615 return None
1716
1817 global_locations = " " .join (
19- f"{ r .check_id } :{ r .path } :{ r .start_line } " for r in global_results
18+ f"{ r .id } :{ r .path } :{ r .start_line } " for r in global_results
2019 )
2120
2221 if len (global_results ) > 1 :
@@ -44,12 +43,7 @@ def d3ify(parts, output, result, _global):
4443 d3ify (parts , new_output , result , _global )
4544 else :
4645 name = f"ln { result .start_line } : { result .first_line } "
47-
48- if _global :
49- fill = _global .rd_fill
50- else :
51- fill = result .rd_fill
52-
46+ fill = _global .rd_fill if _global else result .rd_fill
5347 check_node = {"name" : name , "fill" : fill , "title" : result .lines }
5448 new_node .setdefault ("children" , []).append (check_node )
5549
@@ -66,17 +60,18 @@ def merge_d3_results(d1s, d2s):
6660
6761
6862def main (args ):
69- logger .info ("Reading input file %s" , args .input .name )
70- data = json .load (args .input )
63+ logger .info ("Processing input file %s" , args .input .name )
64+
65+ output_cls = types .CodeQLOutput if args .codeql else types .SemgrepOutput
66+ output = output_cls .from_fd (args .input )
67+ results = output .results
7168
72- semgrep_results = [types .SemgrepResult (r ) for r in data ["results" ]]
73- counts = collections .Counter ([r .check_id for r in semgrep_results ])
74- count_output = " " .join (f"{ k } ={ v } " for k , v in counts .items ())
75- logger .info ("Finding rule counts: %s" , count_output )
69+ for result_id , count in collections .Counter ([r .id for r in results ]).items ():
70+ logger .info ("Found %d results for id %s" , count , result_id )
7671
7772 results_by_type = {
7873 key : list (group )
79- for key , group in util .sorted_groupby (semgrep_results , key = lambda r : r .rd_type )
74+ for key , group in util .sorted_groupby (results , key = lambda r : r .rd_type )
8075 }
8176
8277 global_results = results_by_type .get (types .ResultType .GLOBAL .value , {})
@@ -86,7 +81,7 @@ def main(args):
8681 d3_results = []
8782 for result in results_by_type .get (types .ResultType .ROUTE .value , []):
8883 path = pathlib .PurePath (result .path )
89- logger .debug ("Processing %s:%s:%s" , result .check_id , path , result .start_line )
84+ logger .debug ("Processing %s:%s:%s" , result .id , path , result .start_line )
9085 root , * _ = path .parts
9186 root_paths .add (root )
9287 output = []
0 commit comments