mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-06 05:40:38 +08:00
Refactor publish_persistent_comment method to include name parameter
This commit is contained in:
@ -160,7 +160,7 @@ class BitbucketProvider(GitProvider):
|
|||||||
def get_comment_url(self, comment):
|
def get_comment_url(self, comment):
|
||||||
return comment.data['links']['html']['href']
|
return comment.data['links']['html']['href']
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'):
|
||||||
try:
|
try:
|
||||||
for comment in self.pr.comments():
|
for comment in self.pr.comments():
|
||||||
body = comment.raw
|
body = comment.raw
|
||||||
@ -168,15 +168,15 @@ class BitbucketProvider(GitProvider):
|
|||||||
latest_commit_url = self.get_latest_commit_url()
|
latest_commit_url = self.get_latest_commit_url()
|
||||||
comment_url = self.get_comment_url(comment)
|
comment_url = self.get_comment_url(comment)
|
||||||
if update_header:
|
if update_header:
|
||||||
updated_header = f"{initial_header}\n\n### (review updated until commit {latest_commit_url})\n"
|
updated_header = f"{initial_header}\n\n### ({name.capitalize()} updated until commit {latest_commit_url})\n"
|
||||||
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
get_logger().info(f"Persistent mode- updating comment {comment_url} to latest review message")
|
get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message")
|
||||||
d = {"content": {"raw": pr_comment_updated}}
|
d = {"content": {"raw": pr_comment_updated}}
|
||||||
response = comment._update_data(comment.put(None, data=d))
|
response = comment._update_data(comment.put(None, data=d))
|
||||||
self.publish_comment(
|
self.publish_comment(
|
||||||
f"**[Persistent review]({comment_url})** updated to latest commit {latest_commit_url}")
|
f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}")
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to update persistent review, error: {e}")
|
get_logger().exception(f"Failed to update persistent review, error: {e}")
|
||||||
|
@ -116,7 +116,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_header: str, update_header: bool):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool, name='review'):
|
||||||
self.publish_comment(pr_comment)
|
self.publish_comment(pr_comment)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -171,7 +171,7 @@ class GithubProvider(GitProvider):
|
|||||||
def get_comment_url(self, comment) -> str:
|
def get_comment_url(self, comment) -> str:
|
||||||
return comment.html_url
|
return comment.html_url
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'):
|
||||||
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
|
||||||
@ -179,14 +179,14 @@ class GithubProvider(GitProvider):
|
|||||||
latest_commit_url = self.get_latest_commit_url()
|
latest_commit_url = self.get_latest_commit_url()
|
||||||
comment_url = self.get_comment_url(comment)
|
comment_url = self.get_comment_url(comment)
|
||||||
if update_header:
|
if update_header:
|
||||||
updated_header = f"{initial_header}\n\n### (review updated until commit {latest_commit_url})\n"
|
updated_header = f"{initial_header}\n\n### ({name.capitalize()} updated until commit {latest_commit_url})\n"
|
||||||
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
get_logger().info(f"Persistent mode- updating comment {comment_url} to latest review message")
|
get_logger().info(f"Persistent mode- updating comment {comment_url} to latest review message")
|
||||||
response = comment.edit(pr_comment_updated)
|
response = comment.edit(pr_comment_updated)
|
||||||
self.publish_comment(
|
self.publish_comment(
|
||||||
f"**[Persistent review]({comment_url})** updated to latest commit {latest_commit_url}")
|
f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}")
|
||||||
return
|
return
|
||||||
self.publish_comment(pr_comment)
|
self.publish_comment(pr_comment)
|
||||||
|
|
||||||
|
@ -151,21 +151,21 @@ class GitLabProvider(GitProvider):
|
|||||||
def get_comment_url(self, comment):
|
def get_comment_url(self, comment):
|
||||||
return f"{self.mr.web_url}#note_{comment.id}"
|
return f"{self.mr.web_url}#note_{comment.id}"
|
||||||
|
|
||||||
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True):
|
def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'):
|
||||||
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_header):
|
if comment.body.startswith(initial_header):
|
||||||
latest_commit_url = self.get_latest_commit_url()
|
latest_commit_url = self.get_latest_commit_url()
|
||||||
comment_url = self.get_comment_url(comment)
|
comment_url = self.get_comment_url(comment)
|
||||||
if update_header:
|
if update_header:
|
||||||
updated_header = f"{initial_header}\n\n### (review updated until commit {latest_commit_url})\n"
|
updated_header = f"{initial_header}\n\n### ({name.capitalize()} updated until commit {latest_commit_url})\n"
|
||||||
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
|
||||||
else:
|
else:
|
||||||
pr_comment_updated = pr_comment
|
pr_comment_updated = pr_comment
|
||||||
get_logger().info(f"Persistent mode- updating comment {comment_url} to latest review message")
|
get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message")
|
||||||
response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
|
response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
|
||||||
self.publish_comment(
|
self.publish_comment(
|
||||||
f"**[Persistent review]({comment_url})** updated to latest commit {latest_commit_url}")
|
f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}")
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to update persistent review, error: {e}")
|
get_logger().exception(f"Failed to update persistent review, error: {e}")
|
||||||
|
Reference in New Issue
Block a user