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:
ofir-frd
2025-04-24 09:32:43 +03:00
committed by GitHub
5 changed files with 108 additions and 2 deletions

View File

@ -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

View File

@ -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]):
"""