persistent

s
This commit is contained in:
mrT23
2023-11-08 19:27:16 +02:00
parent f9c832d6cb
commit 14610d5375
8 changed files with 39 additions and 3 deletions

View File

@ -44,6 +44,9 @@ class GitProvider(ABC):
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
pass
def publish_persistent_review(self, pr_comment: str):
self.publish_comment(pr_comment)
@abstractmethod
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
pass

View File

@ -154,10 +154,20 @@ class GithubProvider(GitProvider):
def publish_description(self, pr_title: str, pr_body: str):
self.pr.edit(title=pr_title, body=pr_body)
def publish_persistent_review(self, pr_comment: str):
prev_comments = list(self.pr.get_issue_comments())
for comment in prev_comments:
if comment.body.startswith('## PR Analysis'):
pr_comment_updated = pr_comment.replace('## PR Analysis\n', '## PR Analysis (updated)\n')
response = comment.edit(pr_comment_updated)
return
self.publish_comment(pr_comment)
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
if is_temporary and not get_settings().config.publish_output_progress:
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
return
response = self.pr.create_issue_comment(pr_comment)
if hasattr(response, "user") and hasattr(response.user, "login"):
self.github_user_id = response.user.login

View File

@ -136,6 +136,18 @@ class GitLabProvider(GitProvider):
except Exception as e:
get_logger().exception(f"Could not update merge request {self.id_mr} description: {e}")
def publish_persistent_review(self, pr_comment: str):
try:
for comment in self.mr.notes.list(get_all=True)[::-1]:
if comment.body.startswith('## PR Analysis'):
pr_comment_updated = pr_comment.replace('## PR Analysis\n', '## PR Analysis (updated)\n')
response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
return
except Exception as e:
get_logger().exception(f"Failed to update persistent review, error: {e}")
pass
self.publish_comment(pr_comment)
def publish_comment(self, mr_comment: str, is_temporary: bool = False):
comment = self.mr.notes.create({'body': mr_comment})
if is_temporary:

View File

@ -26,6 +26,7 @@ inline_code_comments = false
ask_and_reflect=false
automatic_review=true
remove_previous_review_comment=false
persistent_comment=true
extra_instructions = ""
# specific configurations for incremental review (/review -i)
require_all_thresholds_for_incremental_review=false

View File

@ -117,7 +117,13 @@ class PRReviewer:
if get_settings().config.publish_output:
get_logger().info('Pushing PR review...')
previous_review_comment = self._get_previous_review_comment()
self.git_provider.publish_comment(pr_comment)
# publish the review
if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental:
self.git_provider.publish_persistent_review(pr_comment)
else:
self.git_provider.publish_comment(pr_comment)
self.git_provider.remove_initial_comment()
if previous_review_comment:
self._remove_previous_review_comment(previous_review_comment)
@ -156,7 +162,6 @@ class PRReviewer:
variables["diff"] = self.patches_diff # update diff
environment = Environment(undefined=StrictUndefined)
# set_custom_labels(variables)
system_prompt = environment.from_string(get_settings().pr_review_prompt.system).render(variables)
user_prompt = environment.from_string(get_settings().pr_review_prompt.user).render(variables)