From 7fc41409d47c65f7ec634746a373ccf97e27eb67 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 5 Jul 2024 16:51:35 +0300 Subject: [PATCH 1/2] refresh --- pr_agent/tools/pr_code_suggestions.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index baaa86f9b..18439b808 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -144,9 +144,8 @@ async def run(self): update_header=True, name="suggestions", final_update_message = final_update_message, - max_previous_comments = get_settings().pr_code_suggestions.max_history_len) - if self.progress_response: - self.progress_response.delete() + max_previous_comments = get_settings().pr_code_suggestions.max_history_len, + progress_response = self.progress_response) else: if self.progress_response: @@ -174,7 +173,8 @@ def publish_persistent_comment_with_history(self, pr_comment: str, update_header: bool = True, name='review', final_update_message=True, - max_previous_comments=4): + max_previous_comments=4, + progress_response=None): history_header = f"#### Previous suggestions\n" last_commit_num = self.git_provider.get_latest_commit_url().split('/')[-1][:7] latest_suggestion_header = f"Latest suggestions up to {last_commit_num}" @@ -242,8 +242,11 @@ def publish_persistent_comment_with_history(self, pr_comment: str, pr_comment_updated += f"{prev_suggestion_table}\n" get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message") - - self.git_provider.edit_comment(comment, pr_comment_updated) + if progress_response: # publish to 'progress_response' comment, because it refreshes immediately + comment.delete() + self.git_provider.edit_comment(progress_response, pr_comment_updated) + else: + self.git_provider.edit_comment(comment, pr_comment_updated) return except Exception as e: get_logger().exception(f"Failed to update persistent review, error: {e}") From be18152446715533a5350b01350d79ef9a70b4c5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 5 Jul 2024 17:11:13 +0300 Subject: [PATCH 2/2] refresh --- pr_agent/tools/pr_code_suggestions.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 18439b808..6e10b54fd 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -143,11 +143,10 @@ async def run(self): initial_header="## PR Code Suggestions ✨", update_header=True, name="suggestions", - final_update_message = final_update_message, - max_previous_comments = get_settings().pr_code_suggestions.max_history_len, - progress_response = self.progress_response) + final_update_message=final_update_message, + max_previous_comments=get_settings().pr_code_suggestions.max_history_len, + progress_response=self.progress_response) else: - if self.progress_response: self.git_provider.edit_comment(self.progress_response, body=pr_body) else: @@ -232,6 +231,7 @@ def publish_persistent_comment_with_history(self, pr_comment: str, # Add to the prev_suggestions section last_prev_table = f"\n
{tick}{name.capitalize()}{up_to_commit_txt}\n
{latest_table}\n\n
" prev_suggestion_table = last_prev_table + "\n" + prev_suggestion_table + new_suggestion_table = pr_comment.replace(initial_header, "").strip() pr_comment_updated = f"{initial_header}\n" @@ -243,8 +243,8 @@ def publish_persistent_comment_with_history(self, pr_comment: str, get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message") if progress_response: # publish to 'progress_response' comment, because it refreshes immediately - comment.delete() self.git_provider.edit_comment(progress_response, pr_comment_updated) + comment.delete() else: self.git_provider.edit_comment(comment, pr_comment_updated) return @@ -252,10 +252,11 @@ def publish_persistent_comment_with_history(self, pr_comment: str, get_logger().exception(f"Failed to update persistent review, error: {e}") pass + # if we are here, we did not find a previous comment to update body = pr_comment.replace(initial_header, "").strip() pr_comment = f"{initial_header}\n\n{latest_commit_html_comment}\n\n{body}\n\n" - if found_comment is not None: - self.git_provider.edit_comment(found_comment, pr_comment) + if progress_response: + self.git_provider.edit_comment(progress_response, pr_comment) else: self.git_provider.publish_comment(pr_comment)