From 1b3fb49f9c49367cd82fec1d8d73721382280231 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 8 Oct 2023 16:50:25 +0300 Subject: [PATCH 1/3] publish each suggestion seperatly only on gitlab --- pr_agent/git_providers/gitlab_provider.py | 4 ++++ pr_agent/tools/pr_code_suggestions.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index 2e6f2140..de3762e6 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -196,6 +196,10 @@ class GitLabProvider(GitProvider): return self.last_diff # fallback to last_diff if no relevant diff is found def publish_code_suggestions(self, code_suggestions: list) -> bool: + if len(code_suggestions) > 1: + logging.debug(f"in gitlab we dont currently support publishing multiple code suggestions simultaneously") + return False + for suggestion in code_suggestions: try: body = suggestion['body'] diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index e1d5206c..d49459b0 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -138,8 +138,8 @@ class PRCodeSuggestions: if get_settings().config.verbosity_level >= 2: logging.info(f"Could not parse suggestion: {d}") - # is_successful = self.git_provider.publish_code_suggestions(code_suggestions) - if True: + is_successful = self.git_provider.publish_code_suggestions(code_suggestions) + if not is_successful: # logging.info("Failed to publish code suggestions, trying to publish each suggestion separately") for code_suggestion in code_suggestions: self.git_provider.publish_code_suggestions([code_suggestion]) From e6548f4fe1b06a75848748d9809195a9b371afe7 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 8 Oct 2023 16:57:22 +0300 Subject: [PATCH 2/3] simpler solution --- pr_agent/git_providers/gitlab_provider.py | 5 +---- pr_agent/tools/pr_code_suggestions.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index de3762e6..ae2d621f 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -196,10 +196,6 @@ class GitLabProvider(GitProvider): return self.last_diff # fallback to last_diff if no relevant diff is found def publish_code_suggestions(self, code_suggestions: list) -> bool: - if len(code_suggestions) > 1: - logging.debug(f"in gitlab we dont currently support publishing multiple code suggestions simultaneously") - return False - for suggestion in code_suggestions: try: body = suggestion['body'] @@ -231,6 +227,7 @@ class GitLabProvider(GitProvider): target_file, target_line_no) except Exception as e: logging.exception(f"Could not publish code suggestion:\nsuggestion: {suggestion}\nerror: {e}") + return True def search_line(self, relevant_file, relevant_line_in_file): target_file = None diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index d49459b0..7f0b1264 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -140,7 +140,7 @@ class PRCodeSuggestions: is_successful = self.git_provider.publish_code_suggestions(code_suggestions) if not is_successful: - # logging.info("Failed to publish code suggestions, trying to publish each suggestion separately") + logging.info("Failed to publish code suggestions, trying to publish each suggestion separately") for code_suggestion in code_suggestions: self.git_provider.publish_code_suggestions([code_suggestion]) From da98fd712fb7aaf8d927504a79b5dbbd3fe75726 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 8 Oct 2023 16:58:22 +0300 Subject: [PATCH 3/3] note --- pr_agent/git_providers/gitlab_provider.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index ae2d621f..b8344fd4 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -227,6 +227,8 @@ class GitLabProvider(GitProvider): target_file, target_line_no) except Exception as e: logging.exception(f"Could not publish code suggestion:\nsuggestion: {suggestion}\nerror: {e}") + + # note that we publish suggestions one-by-one. so, if one fails, the rest will still be published return True def search_line(self, relevant_file, relevant_line_in_file):