From f08b20c66774124606001dad4fb497b74629c788 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 21 Nov 2024 13:37:48 +0200 Subject: [PATCH] Improve logging and error handling in Azure DevOps provider for code suggestions --- .../git_providers/azuredevops_provider.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index d1f9b9ca0..1168afaf9 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -67,16 +67,14 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool: relevant_lines_end = suggestion['relevant_lines_end'] if not relevant_lines_start or relevant_lines_start == -1: - if get_settings().config.verbosity_level >= 2: - get_logger().exception( - f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}") + get_logger().warning( + f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}") continue if relevant_lines_end < relevant_lines_start: - if get_settings().config.verbosity_level >= 2: - get_logger().exception(f"Failed to publish code suggestion, " - f"relevant_lines_end is {relevant_lines_end} and " - f"relevant_lines_start is {relevant_lines_start}") + get_logger().warning(f"Failed to publish code suggestion, " + f"relevant_lines_end is {relevant_lines_end} and " + f"relevant_lines_start is {relevant_lines_start}") continue if relevant_lines_end > relevant_lines_start: @@ -95,9 +93,11 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool: "side": "RIGHT", } post_parameters_list.append(post_parameters) + if not post_parameters_list: + return False - try: - for post_parameters in post_parameters_list: + for post_parameters in post_parameters_list: + try: comment = Comment(content=post_parameters["body"], comment_type=1) thread = CommentThread(comments=[comment], thread_context={ @@ -117,15 +117,11 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool: repository_id=self.repo_slug, pull_request_id=self.pr_num ) - if get_settings().config.verbosity_level >= 2: - get_logger().info( - f"Published code suggestion on {self.pr_num} at {post_parameters['path']}" - ) - return True - except Exception as e: - if get_settings().config.verbosity_level >= 2: - get_logger().error(f"Failed to publish code suggestion, error: {e}") - return False + except Exception as e: + get_logger().warning(f"Azure failed to publish code suggestion, error: {e}") + return True + + def get_pr_description_full(self) -> str: return self.pr.description