mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 05:10:38 +08:00
Remove previous review comment on push event
This commit is contained in:
@ -142,10 +142,15 @@ class BitbucketProvider(GitProvider):
|
|||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
try:
|
try:
|
||||||
for comment in self.temp_comments:
|
for comment in self.temp_comments:
|
||||||
self.pr.delete(f"comments/{comment}")
|
self.remove_comment(comment)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
try:
|
||||||
|
self.pr.delete(f"comments/{comment}")
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to remove comment, error: {e}")
|
||||||
|
|
||||||
# funtion to create_inline_comment
|
# funtion to create_inline_comment
|
||||||
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
||||||
|
@ -221,6 +221,9 @@ class CodeCommitProvider(GitProvider):
|
|||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
return "" # not implemented yet
|
return "" # not implemented yet
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
return "" # not implemented yet
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
||||||
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html
|
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html
|
||||||
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
|
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
|
||||||
|
@ -396,5 +396,8 @@ class GerritProvider(GitProvider):
|
|||||||
# shutil.rmtree(self.repo_path)
|
# shutil.rmtree(self.repo_path)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
pass
|
||||||
|
|
||||||
def get_pr_branch(self):
|
def get_pr_branch(self):
|
||||||
return self.repo.head
|
return self.repo.head
|
||||||
|
@ -71,6 +71,10 @@ class GitProvider(ABC):
|
|||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_languages(self):
|
def get_languages(self):
|
||||||
pass
|
pass
|
||||||
|
@ -50,7 +50,7 @@ class GithubProvider(GitProvider):
|
|||||||
def get_incremental_commits(self):
|
def get_incremental_commits(self):
|
||||||
self.commits = list(self.pr.get_commits())
|
self.commits = list(self.pr.get_commits())
|
||||||
|
|
||||||
self.get_previous_review()
|
self.previous_review = self.get_previous_review(full=True, incremental=True)
|
||||||
if self.previous_review:
|
if self.previous_review:
|
||||||
self.incremental.commits_range = self.get_commit_range()
|
self.incremental.commits_range = self.get_commit_range()
|
||||||
# Get all files changed during the commit range
|
# Get all files changed during the commit range
|
||||||
@ -73,13 +73,19 @@ class GithubProvider(GitProvider):
|
|||||||
break
|
break
|
||||||
return self.commits[first_new_commit_index:]
|
return self.commits[first_new_commit_index:]
|
||||||
|
|
||||||
def get_previous_review(self):
|
def get_previous_review(self, *, full: bool, incremental: bool):
|
||||||
self.previous_review = None
|
if not (full or incremental):
|
||||||
|
raise ValueError("At least one of full or incremental must be True")
|
||||||
|
if not getattr(self, "comments", None):
|
||||||
self.comments = list(self.pr.get_issue_comments())
|
self.comments = list(self.pr.get_issue_comments())
|
||||||
|
prefixes = []
|
||||||
|
if full:
|
||||||
|
prefixes.append("## PR Analysis")
|
||||||
|
if incremental:
|
||||||
|
prefixes.append("## Incremental PR Review")
|
||||||
for index in range(len(self.comments) - 1, -1, -1):
|
for index in range(len(self.comments) - 1, -1, -1):
|
||||||
if self.comments[index].body.startswith("## PR Analysis") or self.comments[index].body.startswith("## Incremental PR Review"):
|
if any(self.comments[index].body.startswith(prefix) for prefix in prefixes):
|
||||||
self.previous_review = self.comments[index]
|
return self.comments[index]
|
||||||
break
|
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
if self.incremental.is_incremental and self.file_set:
|
if self.incremental.is_incremental and self.file_set:
|
||||||
@ -218,10 +224,16 @@ class GithubProvider(GitProvider):
|
|||||||
try:
|
try:
|
||||||
for comment in getattr(self.pr, 'comments_list', []):
|
for comment in getattr(self.pr, 'comments_list', []):
|
||||||
if comment.is_temporary:
|
if comment.is_temporary:
|
||||||
comment.delete()
|
self.remove_comment(comment)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to remove initial comment, error: {e}")
|
get_logger().exception(f"Failed to remove initial comment, error: {e}")
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
try:
|
||||||
|
comment.delete()
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to remove comment, error: {e}")
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.pr.title
|
return self.pr.title
|
||||||
|
|
||||||
|
@ -287,10 +287,16 @@ class GitLabProvider(GitProvider):
|
|||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
try:
|
try:
|
||||||
for comment in self.temp_comments:
|
for comment in self.temp_comments:
|
||||||
comment.delete()
|
self.remove_comment(comment)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
try:
|
||||||
|
comment.delete()
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to remove comment, error: {e}")
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.mr.title
|
return self.mr.title
|
||||||
|
|
||||||
|
@ -140,6 +140,9 @@ class LocalGitProvider(GitProvider):
|
|||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
pass # Not applicable to the local git provider, but required by the interface
|
pass # Not applicable to the local git provider, but required by the interface
|
||||||
|
|
||||||
|
def remove_comment(self, comment):
|
||||||
|
pass # Not applicable to the local git provider, but required by the interface
|
||||||
|
|
||||||
def get_languages(self):
|
def get_languages(self):
|
||||||
"""
|
"""
|
||||||
Calculate percentage of languages in repository. Used for hunk prioritisation.
|
Calculate percentage of languages in repository. Used for hunk prioritisation.
|
||||||
|
@ -24,6 +24,7 @@ num_code_suggestions=4
|
|||||||
inline_code_comments = false
|
inline_code_comments = false
|
||||||
ask_and_reflect=false
|
ask_and_reflect=false
|
||||||
automatic_review=true
|
automatic_review=true
|
||||||
|
remove_previous_review_comment=false
|
||||||
extra_instructions = ""
|
extra_instructions = ""
|
||||||
|
|
||||||
[pr_description] # /describe #
|
[pr_description] # /describe #
|
||||||
@ -100,6 +101,7 @@ push_commands = [
|
|||||||
--pr_reviewer.require_estimate_effort_to_review=false \
|
--pr_reviewer.require_estimate_effort_to_review=false \
|
||||||
--pr_reviewer.num_code_suggestions=0 \
|
--pr_reviewer.num_code_suggestions=0 \
|
||||||
--pr_reviewer.inline_code_comments=false \
|
--pr_reviewer.inline_code_comments=false \
|
||||||
|
--pr_reviewer.remove_previous_review_comment=true \
|
||||||
--pr_reviewer.extra_instructions='' \
|
--pr_reviewer.extra_instructions='' \
|
||||||
"""
|
"""
|
||||||
]
|
]
|
||||||
|
@ -114,9 +114,10 @@ class PRReviewer:
|
|||||||
|
|
||||||
if get_settings().config.publish_output:
|
if get_settings().config.publish_output:
|
||||||
get_logger().info('Pushing PR review...')
|
get_logger().info('Pushing PR review...')
|
||||||
|
previous_review_comment = self._get_previous_review_comment()
|
||||||
self.git_provider.publish_comment(pr_comment)
|
self.git_provider.publish_comment(pr_comment)
|
||||||
self.git_provider.remove_initial_comment()
|
self.git_provider.remove_initial_comment()
|
||||||
|
self._remove_previous_review_comment(previous_review_comment)
|
||||||
if get_settings().pr_reviewer.inline_code_comments:
|
if get_settings().pr_reviewer.inline_code_comments:
|
||||||
get_logger().info('Pushing inline code comments...')
|
get_logger().info('Pushing inline code comments...')
|
||||||
self._publish_inline_code_comments()
|
self._publish_inline_code_comments()
|
||||||
@ -318,3 +319,26 @@ class PRReviewer:
|
|||||||
break
|
break
|
||||||
|
|
||||||
return question_str, answer_str
|
return question_str, answer_str
|
||||||
|
|
||||||
|
def _get_previous_review_comment(self):
|
||||||
|
"""
|
||||||
|
Get the previous review comment if it exists.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if get_settings().pr_reviewer.remove_previous_review_comment and hasattr(self.git_provider, "get_previous_review"):
|
||||||
|
return self.git_provider.get_previous_review(
|
||||||
|
full=not self.incremental.is_incremental,
|
||||||
|
incremental=self.incremental.is_incremental,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to get previous review comment, error: {e}")
|
||||||
|
|
||||||
|
def _remove_previous_review_comment(self, comment):
|
||||||
|
"""
|
||||||
|
Get the previous review comment if it exists.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if get_settings().pr_reviewer.remove_previous_review_comment and comment:
|
||||||
|
self.git_provider.remove_comment(comment)
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to remove previous review comment, error: {e}")
|
||||||
|
Reference in New Issue
Block a user