mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
more feedback
This commit is contained in:
@ -153,13 +153,14 @@ class BitbucketProvider(GitProvider):
|
|||||||
self.diff_files = diff_files
|
self.diff_files = diff_files
|
||||||
return diff_files
|
return diff_files
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_text: str, updated_text: str):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: str = True):
|
||||||
try:
|
try:
|
||||||
for comment in self.pr.comments():
|
for comment in self.pr.comments():
|
||||||
body = comment.raw
|
body = comment.raw
|
||||||
if initial_text in body:
|
if initial_header in body:
|
||||||
if updated_text:
|
if update_header:
|
||||||
pr_comment_updated = pr_comment.replace(initial_text, updated_text)
|
updated_header = f"{initial_header}\n\n ### (updated)\n"
|
||||||
|
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
d = {"content": {"raw": pr_comment_updated}}
|
d = {"content": {"raw": pr_comment_updated}}
|
||||||
|
@ -44,7 +44,7 @@ class GitProvider(ABC):
|
|||||||
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_text: str, updated_text: str):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool):
|
||||||
self.publish_comment(pr_comment)
|
self.publish_comment(pr_comment)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -154,16 +154,20 @@ class GithubProvider(GitProvider):
|
|||||||
def publish_description(self, pr_title: str, pr_body: str):
|
def publish_description(self, pr_title: str, pr_body: str):
|
||||||
self.pr.edit(title=pr_title, body=pr_body)
|
self.pr.edit(title=pr_title, body=pr_body)
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_text: str, updated_text: str):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool=True):
|
||||||
prev_comments = list(self.pr.get_issue_comments())
|
prev_comments = list(self.pr.get_issue_comments())
|
||||||
for comment in prev_comments:
|
for comment in prev_comments:
|
||||||
body = comment.body
|
body = comment.body
|
||||||
if body.startswith(initial_text):
|
if body.startswith(initial_header):
|
||||||
if updated_text:
|
latest_commit = self.pr.get_commits().reversed[0].html_url
|
||||||
pr_comment_updated = pr_comment.replace(initial_text, updated_text)
|
if update_header:
|
||||||
|
updated_text = f"{initial_header}\n\n### (review updated to commit {latest_commit})\n"
|
||||||
|
pr_comment_updated = pr_comment.replace(initial_header, updated_text)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
|
get_logger().info(f"Persistent mode- updating comment {comment.html_url} to latest review message")
|
||||||
response = comment.edit(pr_comment_updated)
|
response = comment.edit(pr_comment_updated)
|
||||||
|
self.publish_comment(f"**[Persistent review]({comment.html_url})** updated to latest commit {latest_commit}")
|
||||||
return
|
return
|
||||||
self.publish_comment(pr_comment)
|
self.publish_comment(pr_comment)
|
||||||
|
|
||||||
|
@ -136,12 +136,13 @@ class GitLabProvider(GitProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Could not update merge request {self.id_mr} description: {e}")
|
get_logger().exception(f"Could not update merge request {self.id_mr} description: {e}")
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_text: str, updated_text: str):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: str = True):
|
||||||
try:
|
try:
|
||||||
for comment in self.mr.notes.list(get_all=True)[::-1]:
|
for comment in self.mr.notes.list(get_all=True)[::-1]:
|
||||||
if comment.body.startswith(initial_text):
|
if comment.body.startswith(initial_header):
|
||||||
if updated_text:
|
if update_header:
|
||||||
pr_comment_updated = pr_comment.replace(initial_text, updated_text)
|
updated_header = f"{initial_header}\n\n ### (updated)\n"
|
||||||
|
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
|
response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
|
||||||
|
@ -158,6 +158,9 @@ class PRDescription:
|
|||||||
user=user_prompt
|
user=user_prompt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
|
get_logger().info(f"\nAI response:\n{response}")
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _prepare_data(self):
|
def _prepare_data(self):
|
||||||
|
@ -121,8 +121,8 @@ class PRReviewer:
|
|||||||
# publish the review
|
# publish the review
|
||||||
if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental:
|
if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental:
|
||||||
self.git_provider.publish_persistent_comment(pr_comment,
|
self.git_provider.publish_persistent_comment(pr_comment,
|
||||||
initial_text="## PR Analysis",
|
initial_header="## PR Analysis",
|
||||||
updated_text="## PR Analysis (updated)")
|
update_header=True)
|
||||||
else:
|
else:
|
||||||
self.git_provider.publish_comment(pr_comment)
|
self.git_provider.publish_comment(pr_comment)
|
||||||
|
|
||||||
@ -178,6 +178,9 @@ class PRReviewer:
|
|||||||
user=user_prompt
|
user=user_prompt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
|
get_logger().info(f"\nAI response:\n{response}")
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _prepare_pr_review(self) -> str:
|
def _prepare_pr_review(self) -> str:
|
||||||
|
Reference in New Issue
Block a user