switch the order of when to disable the existing code, to make sure reflection see's the full suggestion (before and after)

This commit is contained in:
Hussam.lawen
2024-10-30 17:09:44 +02:00
parent 2f5e8472b9
commit 6b64924355

View File

@ -367,6 +367,18 @@ class PRCodeSuggestions:
"code_suggestions_feedback": code_suggestions_feedback[i]}) "code_suggestions_feedback": code_suggestions_feedback[i]})
suggestion["score"] = 7 suggestion["score"] = 7
suggestion["score_why"] = "" suggestion["score_why"] = ""
# if the before and after code is the same, clear one of them
try:
if suggestion['existing_code'] == suggestion['improved_code']:
get_logger().debug(
f"edited improved suggestion {i + 1}, because equal to existing code: {suggestion['existing_code']}")
if get_settings().pr_code_suggestions.commitable_code_suggestions:
suggestion['improved_code'] = "" # we need 'existing_code' to locate the code in the PR
else:
suggestion['existing_code'] = ""
except Exception as e:
get_logger().error(f"Error processing suggestion {i + 1}, error: {e}")
else: else:
# get_logger().error(f"Could not self-reflect on suggestions. using default score 7") # get_logger().error(f"Could not self-reflect on suggestions. using default score 7")
for i, suggestion in enumerate(data["code_suggestions"]): for i, suggestion in enumerate(data["code_suggestions"]):
@ -422,13 +434,6 @@ class PRCodeSuggestions:
continue continue
if ('existing_code' in suggestion) and ('improved_code' in suggestion): if ('existing_code' in suggestion) and ('improved_code' in suggestion):
if suggestion['existing_code'] == suggestion['improved_code']:
get_logger().debug(
f"edited improved suggestion {i + 1}, because equal to existing code: {suggestion['existing_code']}")
if get_settings().pr_code_suggestions.commitable_code_suggestions:
suggestion['improved_code'] = "" # we need 'existing_code' to locate the code in the PR
else:
suggestion['existing_code'] = ""
suggestion = self._truncate_if_needed(suggestion) suggestion = self._truncate_if_needed(suggestion)
one_sentence_summary_list.append(suggestion['one_sentence_summary']) one_sentence_summary_list.append(suggestion['one_sentence_summary'])
suggestion_list.append(suggestion) suggestion_list.append(suggestion)