Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,12 @@ def build_rich_context(
for item in truncated_items:
# 根据触发类型决定包含哪些历史
trigger_type = trigger_node.type if trigger_node else None

# 如果是review或review_comment触发,采用test_context.py的更精确过滤逻辑
if trigger_type in ["review", "review_comment"]:
# 基于test_context.py修复:只保留与当前review相关的项目
trigger_review_id = trigger_node.review_id if trigger_node.review_id else trigger_node.id

if item.type == "review":
# 只包含当前触发的review(test_context.py的精确过滤)
if item.id == trigger_review_id:
Expand All @@ -670,7 +670,7 @@ def build_rich_context(
logger.info(f"Including review comment {item.id} for review {trigger_review_id}")
# 对于review触发,不保留普通comment(基于test_context.py逻辑)
else:
# 普通触发(comment):只处理comment和review,不处理review_comment
# 普通触发(comment):包含所有评论和最新批次的reviews
if item.type == "comment":
comments_history.append({
"id": item.id,
Expand All @@ -680,13 +680,23 @@ def build_rich_context(
"type": item.type
})
elif item.type == "review":
# 包含所有经过智能截断的reviews(最新批次)
reviews_history.append({
"id": item.id,
"user": item.user,
"body": item.body,
"state": item.state,
"submitted_at": item.created_at
})
elif item.type == "review_comment" and item.review_id:
# 包含所有经过智能截断的review comments(最新批次)
review_comments_batch.append({
"id": item.id,
"user": item.user,
"body": item.body,
"path": item.path,
"diff_hunk": item.diff_hunk
})
Comment on lines 682 to +699
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for creating history dictionaries for review and review_comment is duplicated. The logic for creating a review dictionary here is also present in lines 652-658. Similarly, the logic for review_comment added in this PR is a duplicate of the logic in lines 663-669. This code duplication can make future maintenance harder, as any changes would need to be applied in multiple places.

To improve maintainability, consider refactoring this by creating helper functions to build these dictionary objects, thus avoiding repetition.


if comments_history:
context.comments_history = comments_history
Expand Down