From 22d17985a1df61f705edd28cad1d906f2e271d14 Mon Sep 17 00:00:00 2001 From: zmeir Date: Sun, 7 Jan 2024 16:00:44 +0200 Subject: [PATCH 01/11] Less noisy fallback for `publish_code_suggestions` in case of invalid comments As a first option, `publish_code_suggestions` will try to post all review comments in a single GitHub review. This is preferred because it will group all comments together in the GitHub UI under the same review, and will trigger just one notification for any viewers of the PR. If just one of the comments is malformed, the entire API request will fail and none of the comments will be posted to the PR. In the current implementation, the fallback mechanism is to just post each comment separately with `try/except` and skip the invalid comments. This works, but potentially creates a lot of noise in the PR as each comment is posted as in a separate review, creating multiple notifications. This suggested fallback is based on a similar idea, but without creating multiple review notifications. The it works is by iterating over the potential comments, and starting a PENDING review for the current comment. The review is not submitted and does not trigger a notification, but it is verified against the GitHub API, and so we can verify if the comment is valid. After checking all comments we then submit a single review with all the verified comments which is guaranteed to succeed. The end result is having the exact same comments posted to the PR as with the current fallback method, but the downside is having twice as many API calls (for each comment we have 1 extra API call to delete the pending review). --- pr_agent/git_providers/github_provider.py | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index a6ffbcdf..0ca5e1ff 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -271,7 +271,40 @@ class GithubProvider(GitProvider): except Exception as e: if get_settings().config.verbosity_level >= 2: get_logger().error(f"Failed to publish code suggestion, error: {e}") - return False + if getattr(e, "status", None) == 422 and getattr(e, "data", {}).get("message", None) == "Unprocessable Entity": + pass # trying to find the bad comment + else: + return False + try: + import time + verified_comments = [] + invalid_comments = [] + for comment in post_parameters_list: + time.sleep(1) # for avoiding secondary rate limit + try: + headers, data = self.pr._requester.requestJsonAndCheck( + "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) + ) + pending_review_id = data["id"] + verified_comments.append(comment) + except Exception as e: + invalid_comments.append((comment, e)) + pending_review_id = None + if pending_review_id is not None: + try: + self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") + except Exception as e: + pass + if verified_comments: + self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) + if invalid_comments: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Invalid comments: {invalid_comments}") + return True + except Exception as e: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to publish code suggestion fallback, error: {e}") + return False def remove_initial_comment(self): try: From b0bffdec84ae21154577a810c4cc08051fe5785a Mon Sep 17 00:00:00 2001 From: zmeir Date: Mon, 8 Jan 2024 12:00:20 +0200 Subject: [PATCH 02/11] Refactor and add configuration toggle --- pr_agent/git_providers/github_provider.py | 89 ++++++++++++++--------- pr_agent/settings/configuration.toml | 1 + 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 0ca5e1ff..11354ce9 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -222,7 +222,57 @@ class GithubProvider(GitProvider): return dict(body=body, path=path, position=position) if subject_type == "LINE" else {} def publish_inline_comments(self, comments: list[dict]): - self.pr.create_review(commit=self.last_commit_id, comments=comments) + try: + self.pr.create_review(commit=self.last_commit_id, comments=comments) + except Exception as e: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to publish inline comments, error: {e}") + if ( + getattr(e, "status", None) == 422 + and getattr(e, "data", {}).get("message", None) == "Unprocessable Entity" + and get_settings().github.publish_inline_comments_fallback_with_verification + ): + pass # continue to try _publish_inline_comments_fallback_with_verification + else: + raise e + try: + self._publish_inline_comments_fallback_with_verification(comments) + except Exception as e: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to publish inline code comments fallback, error: {e}") + raise e + + def _publish_inline_comments_fallback_with_verification(self, comments): + """ + Check each inline comment separately against the GitHub API and discard of invalid comments, + then publish all the remaining valid comments in a single review. + """ + import time + + verified_comments = [] + invalid_comments = [] + for comment in comments: + time.sleep(1) # for avoiding secondary rate limit + try: + headers, data = self.pr._requester.requestJsonAndCheck( + "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) + ) + pending_review_id = data["id"] + verified_comments.append(comment) + except Exception as e: + invalid_comments.append((comment, e)) + pending_review_id = None + if pending_review_id is not None: + try: + self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") + except Exception as e: + pass + if invalid_comments and get_settings().config.verbosity_level >= 2: + get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") + if verified_comments: + self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) + elif get_settings().config.verbosity_level >= 2: + get_logger().error("Dropped all comments - no verified comments left to publish") def publish_code_suggestions(self, code_suggestions: list) -> bool: """ @@ -266,45 +316,12 @@ class GithubProvider(GitProvider): post_parameters_list.append(post_parameters) try: - self.pr.create_review(commit=self.last_commit_id, comments=post_parameters_list) + self.publish_inline_comments(post_parameters_list) return True except Exception as e: if get_settings().config.verbosity_level >= 2: get_logger().error(f"Failed to publish code suggestion, error: {e}") - if getattr(e, "status", None) == 422 and getattr(e, "data", {}).get("message", None) == "Unprocessable Entity": - pass # trying to find the bad comment - else: - return False - try: - import time - verified_comments = [] - invalid_comments = [] - for comment in post_parameters_list: - time.sleep(1) # for avoiding secondary rate limit - try: - headers, data = self.pr._requester.requestJsonAndCheck( - "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) - ) - pending_review_id = data["id"] - verified_comments.append(comment) - except Exception as e: - invalid_comments.append((comment, e)) - pending_review_id = None - if pending_review_id is not None: - try: - self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") - except Exception as e: - pass - if verified_comments: - self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) - if invalid_comments: - if get_settings().config.verbosity_level >= 2: - get_logger().error(f"Invalid comments: {invalid_comments}") - return True - except Exception as e: - if get_settings().config.verbosity_level >= 2: - get_logger().error(f"Failed to publish code suggestion fallback, error: {e}") - return False + return False def remove_initial_comment(self): try: diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 2479053f..8b05dcfe 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -93,6 +93,7 @@ extra_instructions = "" deployment_type = "user" ratelimit_retries = 5 base_url = "https://api.github.com" +publish_inline_comments_fallback_with_verification = true [github_action] # auto_review = true # set as env var in .github/workflows/pr-agent.yaml From 2bb5ae8c0dce18a17530e360261b69a81f68689d Mon Sep 17 00:00:00 2001 From: zmeir Date: Mon, 8 Jan 2024 13:05:10 +0200 Subject: [PATCH 03/11] Remove redundant condition (status 422 already means the same) --- pr_agent/git_providers/github_provider.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 11354ce9..64d45f43 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -229,7 +229,6 @@ class GithubProvider(GitProvider): get_logger().error(f"Failed to publish inline comments, error: {e}") if ( getattr(e, "status", None) == 422 - and getattr(e, "data", {}).get("message", None) == "Unprocessable Entity" and get_settings().github.publish_inline_comments_fallback_with_verification ): pass # continue to try _publish_inline_comments_fallback_with_verification From 28c5ad1d8be9f2765da7ee9a0465170bc69cff6a Mon Sep 17 00:00:00 2001 From: zmeir Date: Mon, 8 Jan 2024 13:06:03 +0200 Subject: [PATCH 04/11] nit --- pr_agent/git_providers/github_provider.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 64d45f43..80330224 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -247,7 +247,6 @@ class GithubProvider(GitProvider): then publish all the remaining valid comments in a single review. """ import time - verified_comments = [] invalid_comments = [] for comment in comments: From 19c14b940e01db100c592d634b0598a33b1f434e Mon Sep 17 00:00:00 2001 From: zmeir Date: Tue, 9 Jan 2024 09:54:29 +0200 Subject: [PATCH 05/11] Try fixing invalid inline comments --- pr_agent/git_providers/github_provider.py | 51 +++++++++++++++++++---- pr_agent/settings/configuration.toml | 1 + 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 80330224..54f016cb 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -241,11 +241,27 @@ class GithubProvider(GitProvider): get_logger().error(f"Failed to publish inline code comments fallback, error: {e}") raise e - def _publish_inline_comments_fallback_with_verification(self, comments): + def _publish_inline_comments_fallback_with_verification(self, comments: list[dict]): """ Check each inline comment separately against the GitHub API and discard of invalid comments, then publish all the remaining valid comments in a single review. + For invalid comments, also try removing the suggestion part and posting the comment just on the first line. """ + verified_comments, invalid_comments = self._verify_inline_comments(comments) + if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: + fixed_comments = self._try_fix_invalid_inline_comments([comment for comment, _ in invalid_comments]) + verified_fixed_comments, invalid_fixed_comments = self._verify_inline_comments(fixed_comments) + verified_comments += verified_fixed_comments + invalid_comments += invalid_fixed_comments + if invalid_comments and get_settings().config.verbosity_level >= 2: + get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") + if verified_comments: + self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) + elif get_settings().config.verbosity_level >= 2: + get_logger().error("Dropped all comments - no verified comments left to publish") + + def _verify_inline_comments(self, comments: list[dict]) -> tuple[list[dict], list[tuple[dict, Exception]]]: + """Very each comment against the GitHub API and return 2 lists: 1 of verified and 1 of invalid comments""" import time verified_comments = [] invalid_comments = [] @@ -265,12 +281,33 @@ class GithubProvider(GitProvider): self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") except Exception as e: pass - if invalid_comments and get_settings().config.verbosity_level >= 2: - get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") - if verified_comments: - self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) - elif get_settings().config.verbosity_level >= 2: - get_logger().error("Dropped all comments - no verified comments left to publish") + return verified_comments, invalid_comments + + def _try_fix_invalid_inline_comments(self, invalid_comments: list[dict]) -> list[dict]: + """ + Try fixing invalid comments by removing the suggestion part and setting the comment just on the first line. + Return only comments that have been modified in some way. + This is a best-effort attempt to fix invalid comments, and should be verified accordingly. + """ + import copy + fixed_comments = [] + for comment in invalid_comments: + try: + fixed_comment = copy.copy(comment) # avoid modifying the original comment dict for later logging + if "suggestion```" in comment["body"]: + fixed_comment["body"] = comment["body"].split("suggestion```")[0] + if "start_line" in comment: + fixed_comment["line"] = comment["start_line"] + del fixed_comment["start_line"] + if "start_side" in comment: + fixed_comment["side"] = comment["start_side"] + del fixed_comment["start_side"] + if fixed_comment != comment: + fixed_comments.append(fixed_comment) + except Exception as e: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to fix inline comment, error: {e}") + return fixed_comments def publish_code_suggestions(self, code_suggestions: list) -> bool: """ diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 8b05dcfe..bc28a4ff 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -94,6 +94,7 @@ deployment_type = "user" ratelimit_retries = 5 base_url = "https://api.github.com" publish_inline_comments_fallback_with_verification = true +try_fix_invalid_inline_comments = true [github_action] # auto_review = true # set as env var in .github/workflows/pr-agent.yaml From b9951fce628ca6ed4ab68d84f245012cd8be97b4 Mon Sep 17 00:00:00 2001 From: zmeir Date: Wed, 10 Jan 2024 11:59:45 +0200 Subject: [PATCH 06/11] Typo when parsing the suggestion part --- pr_agent/git_providers/github_provider.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 54f016cb..c3e79eb1 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -294,8 +294,8 @@ class GithubProvider(GitProvider): for comment in invalid_comments: try: fixed_comment = copy.copy(comment) # avoid modifying the original comment dict for later logging - if "suggestion```" in comment["body"]: - fixed_comment["body"] = comment["body"].split("suggestion```")[0] + if "```suggestion" in comment["body"]: + fixed_comment["body"] = comment["body"].split("```suggestion")[0] if "start_line" in comment: fixed_comment["line"] = comment["start_line"] del fixed_comment["start_line"] From d6f4c1638d73b2c64546f48655cb00ffe5a448c1 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 14 Jan 2024 10:49:05 +0200 Subject: [PATCH 07/11] feat: Refactor comment verification in github_provider.py --- pr_agent/git_providers/github_provider.py | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index c3e79eb1..ab9616a3 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -1,3 +1,4 @@ +import time import hashlib from datetime import datetime from typing import Optional, Tuple @@ -223,6 +224,7 @@ class GithubProvider(GitProvider): def publish_inline_comments(self, comments: list[dict]): try: + # publish all comments in a single message self.pr.create_review(commit=self.last_commit_id, comments=comments) except Exception as e: if get_settings().config.verbosity_level >= 2: @@ -260,27 +262,35 @@ class GithubProvider(GitProvider): elif get_settings().config.verbosity_level >= 2: get_logger().error("Dropped all comments - no verified comments left to publish") + def _verif_comment(self, comment: dict): + is_verified = False + e = None + try: + headers, data = self.pr._requester.requestJsonAndCheck( + "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) + ) + pending_review_id = data["id"] + is_verified = True + except Exception as e: + is_verified = False + pending_review_id = None + if pending_review_id is not None: + try: + self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") + except Exception as e: + pass + return is_verified, e def _verify_inline_comments(self, comments: list[dict]) -> tuple[list[dict], list[tuple[dict, Exception]]]: """Very each comment against the GitHub API and return 2 lists: 1 of verified and 1 of invalid comments""" - import time verified_comments = [] invalid_comments = [] for comment in comments: time.sleep(1) # for avoiding secondary rate limit - try: - headers, data = self.pr._requester.requestJsonAndCheck( - "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) - ) - pending_review_id = data["id"] + is_verified, e = self._verif_comment(comment) + if is_verified: verified_comments.append(comment) - except Exception as e: + else: invalid_comments.append((comment, e)) - pending_review_id = None - if pending_review_id is not None: - try: - self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") - except Exception as e: - pass return verified_comments, invalid_comments def _try_fix_invalid_inline_comments(self, invalid_comments: list[dict]) -> list[dict]: From 7377f4e4b2a20d5f814fa6d2e79e064e01b1c6ad Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 14 Jan 2024 11:49:51 +0200 Subject: [PATCH 08/11] feat: Refactor comment verification in github_provider.py --- pr_agent/git_providers/github_provider.py | 82 +++++++++++++++-------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index ab9616a3..dd5fa27c 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -222,26 +222,29 @@ class GithubProvider(GitProvider): path = relevant_file.strip() return dict(body=body, path=path, position=position) if subject_type == "LINE" else {} - def publish_inline_comments(self, comments: list[dict]): + def publish_inline_comments(self, comments: list[dict], disable_fallback: bool = False): try: # publish all comments in a single message self.pr.create_review(commit=self.last_commit_id, comments=comments) except Exception as e: if get_settings().config.verbosity_level >= 2: - get_logger().error(f"Failed to publish inline comments, error: {e}") + get_logger().error(f"Failed to publish inline comments") + if ( getattr(e, "status", None) == 422 and get_settings().github.publish_inline_comments_fallback_with_verification + and not disable_fallback ): pass # continue to try _publish_inline_comments_fallback_with_verification else: raise e - try: - self._publish_inline_comments_fallback_with_verification(comments) - except Exception as e: - if get_settings().config.verbosity_level >= 2: - get_logger().error(f"Failed to publish inline code comments fallback, error: {e}") - raise e + + try: + self._publish_inline_comments_fallback_with_verification(comments) + except Exception as e: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to publish inline code comments fallback, error: {e}") + raise e def _publish_inline_comments_fallback_with_verification(self, comments: list[dict]): """ @@ -249,44 +252,69 @@ class GithubProvider(GitProvider): then publish all the remaining valid comments in a single review. For invalid comments, also try removing the suggestion part and posting the comment just on the first line. """ - verified_comments, invalid_comments = self._verify_inline_comments(comments) - if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: - fixed_comments = self._try_fix_invalid_inline_comments([comment for comment, _ in invalid_comments]) - verified_fixed_comments, invalid_fixed_comments = self._verify_inline_comments(fixed_comments) - verified_comments += verified_fixed_comments - invalid_comments += invalid_fixed_comments - if invalid_comments and get_settings().config.verbosity_level >= 2: - get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") - if verified_comments: - self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) - elif get_settings().config.verbosity_level >= 2: - get_logger().error("Dropped all comments - no verified comments left to publish") + verified_comments, invalid_comments = self._verify_code_comments(comments) - def _verif_comment(self, comment: dict): + # publish as a group verified comments + if verified_comments: + try: + self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) + except: + pass + + # try to publish one by one invalid comments, as a one-line comment + if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: + fixed_comments_as_one_liner = self._try_fix_invalid_inline_comments( + [comment for comment, _ in invalid_comments]) + for comment in fixed_comments_as_one_liner: + try: + self.publish_inline_comments([comment], disable_fallback=True) + if get_settings().config.verbosity_level >= 2: + get_logger().info(f"Published invalid comment as a single line comment: {comment}") + except: + if get_settings().config.verbosity_level >= 2: + get_logger().error(f"Failed to publish invalid comment as a single line comment: {comment}") + + # verified_comments, invalid_comments = self._verify_inline_comments(comments) + # if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: + # fixed_comments = self._try_fix_invalid_inline_comments([comment for comment, _ in invalid_comments]) + # verified_fixed_comments, invalid_fixed_comments = self._verify_inline_comments(fixed_comments) + # verified_comments += verified_fixed_comments + # invalid_comments += invalid_fixed_comments + # if invalid_comments and get_settings().config.verbosity_level >= 2: + # get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") + # if verified_comments: + # self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) + # elif get_settings().config.verbosity_level >= 2: + # get_logger().error("Dropped all comments - no verified comments left to publish") + + def _verify_code_comment(self, comment: dict): is_verified = False e = None try: + # event ="" # By leaving this blank, you set the review action state to PENDING + input = dict(commit_id=self.last_commit_id.sha, comments=[comment]) headers, data = self.pr._requester.requestJsonAndCheck( - "POST", f"{self.pr.url}/reviews", input=dict(commit_id=self.last_commit_id.sha, comments=[comment]) - ) + "POST", f"{self.pr.url}/reviews", input=input) pending_review_id = data["id"] is_verified = True - except Exception as e: + except Exception as err: is_verified = False pending_review_id = None + e = err if pending_review_id is not None: try: self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}") - except Exception as e: + except Exception: pass return is_verified, e - def _verify_inline_comments(self, comments: list[dict]) -> tuple[list[dict], list[tuple[dict, Exception]]]: + + def _verify_code_comments(self, comments: list[dict]) -> tuple[list[dict], list[tuple[dict, Exception]]]: """Very each comment against the GitHub API and return 2 lists: 1 of verified and 1 of invalid comments""" verified_comments = [] invalid_comments = [] for comment in comments: time.sleep(1) # for avoiding secondary rate limit - is_verified, e = self._verif_comment(comment) + is_verified, e = self._verify_code_comment(comment) if is_verified: verified_comments.append(comment) else: From 9f5c2e5f178c7ee39768d14b0cd0c913f1e47838 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 14 Jan 2024 11:55:07 +0200 Subject: [PATCH 09/11] feat: Refactor comment verification in github_provider.py --- pr_agent/git_providers/github_provider.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index dd5fa27c..75c44448 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -254,14 +254,14 @@ class GithubProvider(GitProvider): """ verified_comments, invalid_comments = self._verify_code_comments(comments) - # publish as a group verified comments + # publish as a group the verified comments if verified_comments: try: self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) except: pass - # try to publish one by one invalid comments, as a one-line comment + # try to publish one by one the invalid comments as a one-line code comment if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: fixed_comments_as_one_liner = self._try_fix_invalid_inline_comments( [comment for comment, _ in invalid_comments]) From d942bdb8bdc712ac8ad4c623203a8da6223007cf Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 20 Jan 2024 11:56:17 +0200 Subject: [PATCH 10/11] s --- pr_agent/git_providers/github_provider.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 75c44448..b41487fa 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -230,14 +230,11 @@ class GithubProvider(GitProvider): if get_settings().config.verbosity_level >= 2: get_logger().error(f"Failed to publish inline comments") - if ( - getattr(e, "status", None) == 422 - and get_settings().github.publish_inline_comments_fallback_with_verification - and not disable_fallback - ): + if (getattr(e, "status", None) == 422 + and get_settings().github.publish_inline_comments_fallback_with_verification and not disable_fallback): pass # continue to try _publish_inline_comments_fallback_with_verification else: - raise e + raise e # will end up with publishing the comments one by one try: self._publish_inline_comments_fallback_with_verification(comments) @@ -274,19 +271,6 @@ class GithubProvider(GitProvider): if get_settings().config.verbosity_level >= 2: get_logger().error(f"Failed to publish invalid comment as a single line comment: {comment}") - # verified_comments, invalid_comments = self._verify_inline_comments(comments) - # if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: - # fixed_comments = self._try_fix_invalid_inline_comments([comment for comment, _ in invalid_comments]) - # verified_fixed_comments, invalid_fixed_comments = self._verify_inline_comments(fixed_comments) - # verified_comments += verified_fixed_comments - # invalid_comments += invalid_fixed_comments - # if invalid_comments and get_settings().config.verbosity_level >= 2: - # get_logger().error(f"Dropped {len(invalid_comments)} invalid comments: {invalid_comments}") - # if verified_comments: - # self.pr.create_review(commit=self.last_commit_id, comments=verified_comments) - # elif get_settings().config.verbosity_level >= 2: - # get_logger().error("Dropped all comments - no verified comments left to publish") - def _verify_code_comment(self, comment: dict): is_verified = False e = None From e54388d807c902744c3cc692104af40daacc262a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 20 Jan 2024 11:59:45 +0200 Subject: [PATCH 11/11] s --- pr_agent/git_providers/github_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index b41487fa..aaf1f386 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -315,7 +315,7 @@ class GithubProvider(GitProvider): fixed_comments = [] for comment in invalid_comments: try: - fixed_comment = copy.copy(comment) # avoid modifying the original comment dict for later logging + fixed_comment = copy.deepcopy(comment) # avoid modifying the original comment dict for later logging if "```suggestion" in comment["body"]: fixed_comment["body"] = comment["body"].split("```suggestion")[0] if "start_line" in comment: