Skip to content

Comments

fix(server.py): include all reviews in PR context when triggered by review#52

Closed
WhiteElephantIsNotARobot wants to merge 4 commits intoWhiteElephant-abc:mainfrom
WhiteElephantIsNotARobot:fix-review-context
Closed

fix(server.py): include all reviews in PR context when triggered by review#52
WhiteElephantIsNotARobot wants to merge 4 commits intoWhiteElephant-abc:mainfrom
WhiteElephantIsNotARobot:fix-review-context

Conversation

@WhiteElephantIsNotARobot
Copy link
Contributor

@WhiteElephantIsNotARobot WhiteElephantIsNotARobot commented Jan 28, 2026

Summary

Previously, when triggered by a review or review_comment, only the specific review that triggered the bot was included in reviews_history. This caused the PR context to not contain review information as expected.

Fix

Now, when triggered by a comment (@mention):

  • All reviews from the truncated timeline are included (latest batch)
  • All review comments from the truncated timeline are included (latest batch)

When triggered by review/review_comment:

  • Only the specific review and its associated review comments are included (precise filtering)

Changes

  • Modified build_rich_context() function in server.py
  • Added review_comment handling for comment trigger type
  • Now all reviews and review comments in the truncated timeline are included when triggered by comment

Fixes #49

🤖 Generated with Claude Code

…eview

Previously, when triggered by a review or review_comment, only the specific
review that triggered the bot was included in reviews_history. This caused
the PR context to not contain review information as expected.

Now, all reviews are included in the timeline and truncated according to
the smart truncation algorithm (3 new, 1 old ratio), which matches the
expected behavior described in issue WhiteElephant-abc#49.

Fixes WhiteElephant-abc#49

Co-Authored-By: Claude (mimo-v2-flash) <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @WhiteElephantIsNotARobot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the bot's generated context for a pull request was incomplete when triggered by a review or review comment. The fix ensures that the bot now incorporates a full history of reviews and their associated comments, adhering to the established timeline truncation rules, thereby providing a richer and more accurate understanding of the pull request's review status.

Highlights

  • Enhanced PR Context for Review Triggers: The pull request context generation logic has been updated to include all relevant reviews and review comments from the truncated timeline when the bot is triggered by a review or review_comment event. Previously, only the specific review that triggered the bot was included.
  • Removal of Specific Review Filtering: The filtering mechanism that restricted the inclusion of reviews and review comments to only those associated with the immediate triggering review ID has been removed. This ensures a more comprehensive history is provided.
  • Alignment with Truncation Algorithm: The change aligns the review inclusion behavior with the existing smart truncation algorithm (3 new, 1 old ratio), ensuring that the context contains the latest batch of reviews or all reviews truncated appropriately.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a bug where the context for a review-triggered event was incomplete. The change in server.py correctly modifies the build_rich_context function to include all reviews and review comments from the truncated timeline, instead of just the single review that triggered the event. This simplification not only fixes the bug but also makes the logic more straightforward. The implementation is correct and aligns with the stated goal. I approve these changes.

Copy link
Owner

@WhiteElephant-abc WhiteElephant-abc left a comment

Choose a reason for hiding this comment

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

@WhiteElephantIsNotARobot 这显然不对,我的要求是在comment中@时应该包含最新批次的review,你赶紧更正

When triggered by a comment (not review/review_comment), now includes:
- comments_history (existing)
- reviews_history (existing)
- review_comments_batch (NEW - was previously excluded)

This ensures that when @ mentioning in a comment, the bot receives
the latest batch of review information including inline code reviews.

Fixes the issue where comment triggers didn't include review_comments.

Co-Authored-By: Claude (mimo-v2-flash) <noreply@anthropic.com>
@WhiteElephantIsNotARobot
Copy link
Contributor Author

已修复。现在当在 comment 中 @ 机器人时,会包含以下信息:

  1. comments_history - 普通评论历史
  2. reviews_history - 审核记录(包含审核状态如 CHANGES_REQUESTED、APPROVED 等)
  3. review_comments_batch - 行内代码评论(包含具体的代码路径和 diff_hunk)- 这是新增的

之前的代码在普通 comment 触发时只处理了 commentreview,现在也包含了 review_comment,这样 bot 就能获得最新批次的 review 信息了。

修改位置:server.py 第 664-690 行

Copy link
Owner

@WhiteElephant-abc WhiteElephant-abc left a comment

Choose a reason for hiding this comment

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

@WhiteElephantIsNotARobot 之前改的review中@的处理逻辑要恢复(注意避免强推)

恢复之前修改的精确过滤逻辑:
- 当是 review 或 review_comment 触发时,只保留与当前 review 相关的项目
- 当是普通 comment 触发时,只处理 comment 和 review,不处理 review_comment

避免强推,保持与上游仓库的兼容性。

Co-Authored-By: Claude (mimo-v2-flash) <noreply@anthropic.com>
@WhiteElephantIsNotARobot
Copy link
Contributor Author

已恢复 review 中 @ 的处理逻辑。

修改内容:

  • 当是 review 或 review_comment 触发时,只保留与当前 review 相关的项目(精确过滤)
  • 当是普通 comment 触发时,只处理 comment 和 review,不处理 review_comment
  • 避免强推,保持与上游仓库的兼容性

修改已提交并推送到 fix-review-context 分支。

Copy link
Owner

@WhiteElephant-abc WhiteElephant-abc left a comment

Choose a reason for hiding this comment

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

现在diff啥更改都没有了,你回退是不是过头了

@WhiteElephant-abc
Copy link
Owner

When triggered by a comment (@mention), include all review comments
from the truncated timeline (latest batch) in addition to reviews.

Changes:
- Added review_comment handling for comment trigger type
- Updated comment to reflect the new behavior

Fixes WhiteElephant-abc#49

Co-Authored-By: Claude (mimo-v2-flash) <noreply@anthropic.com>
@WhiteElephantIsNotARobot
Copy link
Contributor Author

已修复。现在当在 comment 中 @ 机器人时,会包含以下信息:

  1. comments_history - 普通评论历史
  2. reviews_history - 审核记录(包含审核状态如 CHANGES_REQUESTED、APPROVED 等)- 现在包含最新批次的所有 reviews
  3. review_comments_batch - 行内代码评论(包含具体的代码路径和 diff_hunk)- 现在也包含最新批次的所有 review comments

修改内容:

  • 当是 review 或 review_comment 触发时,只保留与当前 review 相关的项目(精确过滤,保持不变)
  • 当是普通 comment 触发时,现在也包含了 review_comment,这样 bot 就能获得最新批次的 review 信息了

修改位置:server.py 第 672-698 行

@WhiteElephant-abc
Copy link
Owner

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the logic for building the context when the bot is triggered by a comment. It now correctly includes all reviews and review comments from the truncated timeline, not just regular comments. The implementation is correct, but I've pointed out an area of code duplication that was exacerbated by this change, which could be refactored for better maintainability. Note that the PR title and summary seem a bit confusing compared to the actual changes, which are well-described in the 'Fix' and 'Changes' sections.

Comment on lines 682 to +699
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
})
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.

@WhiteElephant-abc
Copy link
Owner

@WhiteElephantIsNotARobot 不改代码,向你确认:comment的上下文是否包含且仅包含最新批次的review

@WhiteElephantIsNotARobot
Copy link
Contributor Author

是的,确认如此。

当触发类型是 comment(普通评论 @ 机器人)时, 和 包含的是经过智能截断算法处理后的所有 items(即最新批次):

  1. 评论触发时:包含所有评论 + 最新批次的 reviews + 最新批次的 review comments
  2. review/review_comment 触发时:采用精确过滤,只保留与当前 review 相关的项目

智能截断算法(3新1旧)在 中已经应用,所以 comment 触发时包含的就是最新批次的 review 和 review comments,而不是所有历史。

@WhiteElephantIsNotARobot
Copy link
Contributor Author

是的,确认如此。

当触发类型是 comment(普通评论 @ 机器人)时,reviews_history 和 review_comments_batch 包含的是经过智能截断算法处理后的所有 items(即最新批次):

  1. 评论触发时:包含所有评论 + 最新批次的 reviews + 最新批次的 review comments
  2. review/review_comment 触发时:采用精确过滤,只保留与当前 review 相关的项目

智能截断算法(3新1旧)在 truncated_items 中已经应用,所以 comment 触发时包含的就是最新批次的 review 和 review comments,而不是所有历史。

@WhiteElephant-abc
Copy link
Owner

@WhiteElephantIsNotARobot review批次也有智能截断吗

@WhiteElephantIsNotARobot
Copy link
Contributor Author

是的,确认如此。

是已经经过智能截断算法(3新1旧)处理后的结果。当触发类型是 时:

  1. **** - 包含 中所有的 类型项目(即最新批次)
  2. **** - 包含 中所有的 类型项目(即最新批次)

所以 review 批次也有智能截断, 这个变量名本身就暗示了它已经过截断处理。comment 触发时包含的就是最新批次的 review 和 review comments,而不是所有历史。

@WhiteElephant-abc
Copy link
Owner

@WhiteElephantIsNotARobot review批次确保不截断,尽量完整保留,无论是comment触发还是review批次中触发

@WhiteElephantIsNotARobot
Copy link
Contributor Author

已关闭 PR #52(fix-review-context),该分支的修改不完整且与需求不符。

已创建新的 PR #62(fix-review-no-truncate),正确实现了需求:

核心修改:review 批次(reviews_history 和 review_comments_batch)确保不截断,尽量完整保留,无论是 comment 触发还是 review 批次中触发。

详细说明见 PR #62 的描述。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pr上下文不包含review

2 participants