@@ -82,55 +82,53 @@ def generate_review_note(change):
8282 log .error (f"GPT error:{ e } " )
8383
8484
85- def chat_review (index , project_id , project_commit_id , content , context , merge_comment_info ):
85+ def chat_review (commit_index , project_id , commit_id , changes , context_info , merge_comment_details ):
8686 log .info ('开始code review' )
87- if index :
88- review_info = f"\n # { index } .commit_id { project_commit_id } \n "
87+ if commit_index :
88+ review_summary = f"\n # { commit_index } .commit_id { commit_id } \n "
8989 else :
90- log .info (f"🚚 mr_changes{ content } " )
90+ log .info (f"🚚 mr_changes{ changes } " )
9191 with concurrent .futures .ThreadPoolExecutor () as executor :
92- results = []
92+ review_results = []
9393 result_lock = threading .Lock ()
9494
95- def process_input ( val ):
96- result = generate_review_note (val )
95+ def process_change ( change ):
96+ result = generate_review_note (change )
9797 with result_lock :
98- results .append (result )
98+ review_results .append (result )
9999
100100 futures = []
101- for change in content :
101+ for change in changes :
102102 if any (change ["new_path" ].endswith (ext ) for ext in ['.py' , '.java' , '.class' , '.vue' , ".go" ]) and not any (
103103 change ["new_path" ].endswith (ext ) for ext in ["mod.go" ]):
104- futures .append (executor .submit (process_input , change ))
104+ futures .append (executor .submit (process_change , change ))
105105 else :
106106 log .info (f"{ change ['new_path' ]} 非目标检测文件!" )
107107
108108 concurrent .futures .wait (futures )
109109
110- return "\n \n " .join (results ) if results else ""
110+ return "\n \n " .join (review_results ) if review_results else ""
111111
112112
113113# 针对于每个 commit 进行 cr
114114@retry (stop_max_attempt_number = 3 , wait_fixed = 2000 )
115- def review_code (project_id , project_commit_id , merge_id , context ):
116- review_info = ""
117- index = 0
118- for commit_id in project_commit_id :
119- index += 1
115+ def review_code (project_id , commit_ids , merge_request_id , context ):
116+ review_summary = ""
117+ for index , commit_id in enumerate (commit_ids , start = 1 ):
120118 url = f'{ gitlab_server_url } /api/v4/projects/{ project_id } /repository/commits/{ commit_id } /diff'
121119 log .info (f"开始请求gitlab的{ url } ,commit: { commit_id } 的diff内容" )
122120
123121 response = requests .get (url , headers = headers )
124122 if response .status_code == 200 :
125- content = response .json ()
123+ diff_content = response .json ()
126124 # 开始处理请求的类容
127- log .info (f"开始处理All请求的类容: { content } " )
128- review_info += chat_review (index , project_id , commit_id , content , context , "" )
125+ log .info (f"开始处理All请求的类容: { diff_content } " )
126+ review_summary += chat_review (index , project_id , commit_id , diff_content , context , "" )
129127
130128 else :
131129 log .error (f"请求gitlab的{ url } commit失败,状态码:{ response .status_code } " )
132130 raise Exception (f"请求gitlab的{ url } commit失败,状态码:{ response .status_code } " )
133- add_comment_to_mr (project_id , merge_id , review_info )
131+ add_comment_to_mr (project_id , merge_request_id , review_summary )
134132
135133
136134# 针对mr进行cr
0 commit comments