1+ import csv
12import os
23import pathlib
34import subprocess
@@ -63,8 +64,6 @@ def gen_diff(before_sha: str, after_sha: str):
6364 after_sha ,
6465 "--outputCsv" ,
6566 csv_result_file ,
66- "--outputJson" ,
67- json_result_file ,
6867 ]
6968 )
7069
@@ -73,20 +72,9 @@ def process_with_ai(raw: str) -> str:
7372 req = f"""
7473You are a bot for helping code review.
7574Standard csv report was generated from diff analysis tool.
76- Some descriptions:
77-
78- - it contains all the influenced lines by this commit
79- - each row = each line
80- - RefScope.TotalRefCount: total variable references in this line
81- - RefScope.CrossFileRefCount: variable references by other files
82- - RefScope.CrossDirRefCount: variable references by other directories
83- - FuncRefScope.TotalFuncRefCount: total functions influenced by this line
84- - FuncRefScope.CrossFuncFileRefCount: functions in other files influenced by this line
85- - FUncRefScope.crossFuncDirRefCount: functions in other dirs influenced by this line
8675
8776Here is a csv report below for a specific commit.
8877Evaluate it and indicate the most important parts which reviewers should care.
89- All the file paths should be wrapped with markdown link for navigation.
9078Empty report means that there are no dangerous changes.
9179
9280--- report start ---
@@ -109,6 +97,33 @@ def convert_csv_to_md(csv_file) -> str:
10997 return md_table_raw
11098
11199
100+ def process_csv (csv_file ):
101+ cols = [
102+ "fileName" ,
103+ "affectedLinePercent" ,
104+ "affectedFunctionPercent" ,
105+ "affectedReferencePercent" ,
106+ ]
107+ origin_cols = cols [:1 ]
108+ data_cols = cols [1 :]
109+
110+ with open (csv_file , newline = '' ) as f :
111+ reader = csv .DictReader (f )
112+ rows = list (reader )
113+
114+ with open (csv_file , "w" , newline = '' ) as f :
115+ writer = csv .DictWriter (f , fieldnames = cols )
116+ writer .writeheader ()
117+ for each_row in rows :
118+ row_dict = dict ()
119+ for each_col in origin_cols :
120+ row_dict [each_col ] = each_row [each_col ]
121+ for each_col in data_cols :
122+ row_dict [each_col ] = f"{ round (float (each_row [each_col ]) * 100 , 2 )} %"
123+
124+ writer .writerow (row_dict )
125+
126+
112127def main ():
113128 args = sys .argv [1 :]
114129 lang = args [0 ]
@@ -137,27 +152,25 @@ def main():
137152 with open (csv_result_file , encoding = "utf-8" ) as f :
138153 content = f .read ()
139154
140- ai_content = ""
155+ ai_content = "- "
141156 if not openai_api_key :
142157 logger .warning ("no openai api key found. Use raw data." )
143158 else :
144159 logger .info ("process with openai" )
145160 openai .api_key = openai_api_key
146161 ai_content = process_with_ai (content )
147162
163+ # todo: add to feedback?
164+ logger .info (f"ai resp: { ai_content } " )
165+
148166 repo_name = os .getenv ("GITHUB_REPOSITORY" )
167+ process_csv (csv_result_file )
149168 md_table_raw = convert_csv_to_md (csv_result_file )
150169
151170 final_content = f"""
152171## DiffCtx Report
153172
154- { ai_content }
155-
156- <details><summary>Details</summary>
157-
158173{ md_table_raw }
159-
160- </details>
161174"""
162175 logger .info (f"final comment: { final_content } " )
163176
0 commit comments