mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-19 03:50:40 +08:00
Merge pull request #1687 from benedict-lee/feat/add-conversation-history-on-line-question
Improvement: Enhance ask_line tool by adding PR review comment threads as context
This commit is contained in:
@ -285,6 +285,9 @@ class GitProvider(ABC):
|
||||
|
||||
def get_comment_url(self, comment) -> str:
|
||||
return ""
|
||||
|
||||
def get_review_thread_comments(self, comment_id: int) -> list[dict]:
|
||||
pass
|
||||
|
||||
#### labels operations ####
|
||||
@abstractmethod
|
||||
|
@ -427,7 +427,41 @@ class GithubProvider(GitProvider):
|
||||
self._publish_inline_comments_fallback_with_verification(comments)
|
||||
except Exception as e:
|
||||
get_logger().error(f"Failed to publish inline code comments fallback, error: {e}")
|
||||
raise e
|
||||
raise e
|
||||
|
||||
def get_review_thread_comments(self, comment_id: int) -> list[dict]:
|
||||
"""
|
||||
Retrieves all comments in the same thread as the given comment.
|
||||
|
||||
Args:
|
||||
comment_id: Review comment ID
|
||||
|
||||
Returns:
|
||||
List of comments in the same thread
|
||||
"""
|
||||
try:
|
||||
# Fetch all comments with a single API call
|
||||
all_comments = list(self.pr.get_comments())
|
||||
|
||||
# Find the target comment by ID
|
||||
target_comment = next((c for c in all_comments if c.id == comment_id), None)
|
||||
if not target_comment:
|
||||
return []
|
||||
|
||||
# Get root comment id
|
||||
root_comment_id = target_comment.raw_data.get("in_reply_to_id", target_comment.id)
|
||||
# Build the thread - include the root comment and all replies to it
|
||||
thread_comments = [
|
||||
c for c in all_comments if
|
||||
c.id == root_comment_id or c.raw_data.get("in_reply_to_id") == root_comment_id
|
||||
]
|
||||
|
||||
|
||||
return thread_comments
|
||||
|
||||
except Exception as e:
|
||||
get_logger().exception(f"Failed to get review comments for an inline ask command", artifact={"comment_id": comment_id, "error": e})
|
||||
return []
|
||||
|
||||
def _publish_inline_comments_fallback_with_verification(self, comments: list[dict]):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user