-
Notifications
You must be signed in to change notification settings - Fork 8
实现 Issue #141: 支持Code Review场景下,一次性提交多个review comments的场景 #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Support scenario where reviewers submit multiple pending review comments and then use "/continue" or "/fix" commands in the final review submission. The system now handles pull_request_review events with "/continue" or "/fix" commands by: - Collecting all review comments associated with the review ID - Preserving code position information (file paths, line numbers) - Building complete context for AI to process all issues at once - Responding via PR comment instead of individual review comments Key improvements: - Added GitHub client methods to fetch PR reviews and review comments - Enhanced webhook handler to process pull_request_review events - Implemented batch processing in agent with position-aware context - Supports both multi-comment reviews and review-body-only scenarios Closes #141
/continue 整体完成符合预期,另外我想当pull_request_review 事件接受到"/continue" 或"/fix" 指令时,先去创建一个comment ,表示正在处理,处理完成后,将改动的信息整理后覆盖之前的comment,并且@ 触发pull_request_review 事件的用户 |
…ional commit message for this code review batch processing feature: feat: support batch processing of multiple review comments Add support for processing multiple review comments at once when reviewer submits "/continue" or "/fix" commands. The system now: - Creates a processing status comment with @user mention when command is received - Collects all review comments from the same review ID with position information - Processes all comments together in a single AI request with complete context - Updates the initial comment with results instead of creating multiple comments - Maintains code line position information for accurate context This enables reviewers to submit multiple pending comments and have the AI agent fix all issues in one batch operation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
我已经成功完成了所有任务!根据您的要求,我实现了以下功能: 实现的功能1. 在 GitHub 客户端中添加了更新评论功能
2. 修改了 webhook handler 的 handlePRReview 函数
3. 增强了 agent 的处理功能
4. 完整的 @ 提及用户功能
工作流程
这样确保了用户能实时了解处理状态,同时保持 PR 评论区整洁(不会产生多个评论)。 |
/fix 修复下面问题 github.com/qbox/codeagent/internal/webhookinternal/webhook/handler.go:313:28: undefined: fmt |
Support batch processing of code review comments in pull request reviews. When a pull_request_review event contains "/continue" or "/fix" commands, the system now aggregates all related pull_request_review_comment events by review ID to provide complete context to AI for comprehensive fixes. Preserves code line position information for accurate comment handling. Closes #141
已修复。在 |
/fix travis CI 在执行 test -z "$(gofmt -l .)" |
Support batch processing of multiple review comments in code review scenarios. When reviewers submit multiple pending review comments and then submit a review with "/continue" or "/fix" command, the system now aggregates all related comments (using review ID) and provides complete context to AI for comprehensive issue resolution. Key changes: - Handle pull_request_review events with "/continue" or "/fix" commands - Aggregate related pull_request_review_comment events by review ID - Preserve code position information (line numbers) for each comment - Provide complete context to AI for batch processing of all issues Fixed gofmt formatting issues in agent.go and handler.go. Closes #141
Fixed. The gofmt formatting issues in |
internal/agent/agent.go
Outdated
@@ -735,6 +735,368 @@ func (a *Agent) FixPRFromReviewComment(ctx context.Context, event *github.PullRe | |||
return nil | |||
} | |||
|
|||
// CreateProcessingComment 创建"正在处理"的评论 | |||
func (a *Agent) CreateProcessingComment(ctx context.Context, pr *github.PullRequest, commentBody string) (*github.IssueComment, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要有这个?
没必要先创建状态,一是这浪费github api 额度,另是常规角度来讲,当人提交个code review时,也没必要等待别人(AI)立马干完。 |
internal/agent/agent.go
Outdated
return a.processReviewOnlyWithComment(ctx, event, command, args, commentID, triggerUser) | ||
} | ||
// 更新评论说明没有找到需要处理的内容 | ||
a.updateCommentWithNoContent(ctx, pr, commentID, triggerUser, command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也没必要
internal/agent/agent.go
Outdated
} | ||
|
||
// processReviewOnly 处理只有 review body 没有 comments 的情况 | ||
func (a *Agent) processReviewOnly(ctx context.Context, event *github.PullRequestReviewEvent, command string, args string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个也是多余的
/continue 有几个问题:
|
Implement batch processing for Code Review scenarios where reviewers submit multiple pending review comments and then use "/continue" or "/fix" commands to trigger AI fixes for all comments at once. Key improvements: - Remove unnecessary status comment creation to save GitHub API quota - Process all review comments associated with a review ID as a single batch - Preserve code position information for each review comment - Include @user mentions in AI feedback responses - Clean up unused comment update functions and streamline interaction flow The system now handles pull_request_review events with "/continue" or "/fix" commands by collecting all associated pull_request_review_comment events (linked by review ID) and providing complete context to AI for comprehensive issue resolution. Closes #141
Perfect! I have successfully implemented all the requested changes: Summary of Changes Made1. ✅ Removed unnecessary status creation logic that wastes GitHub API quota
2. ✅ Preserved the @user mention logic in AI feedback
3. ✅ Removed unused code and cleaned up
4. ✅ Improved interaction flow
The code now follows a cleaner pattern where:
All code compiles successfully and maintains the same functionality while being more efficient. |
/fix 有以下几个问题需要修改:
|
internal/agent/agent.go
Outdated
if len(reviewComments) == 0 { | ||
log.Infof("No review comments found for review %d", reviewID) | ||
// 如果没有review comments,但有review body,也应该处理 | ||
if event.Review.GetBody() != "" { | ||
return a.processReviewOnlyWithTriggerUser(ctx, event, command, args, triggerUser) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/continue 当reviewComments 长度为0时,仅仅意味着没有额外的review comments,后续的逻辑处理应该跟有comments是一样的,仅仅是给到AI的上下文有区别。所以这里的代码实现我感觉有问题,不应该存在要另开一个方法 processReviewOnlyWithTriggerUser 来处理的情况。甚至这个方法 processReviewOnlyWithTriggerUser 应该都没必要吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完成重构。主要修改:
- 删除了
processReviewOnlyWithTriggerUser
方法:因为它的逻辑与主流程重复 - 统一了处理逻辑:无论 reviewComments 是否为空,都使用同一个处理流程
- 根据评论数量调整提示词:当没有评论时使用 "Review 说明" 格式,有评论时使用 "批量评论" 格式
- 调整了响应消息:根据是否有评论给出不同的反馈信息
现在的代码逻辑更清晰,避免了重复的方法,处理流程统一。
Remove duplicate processReviewOnlyWithTriggerUser method and unify the handling of review events with or without comments. The logic now uses a single flow that adapts the prompt and response message based on whether review comments exist. Key changes: - Removed processReviewOnlyWithTriggerUser method to eliminate duplication - Unified processing logic in ProcessPRFromReviewWithTriggerUser - Adjusted prompt format based on comment count (Review vs batch comments) - Streamlined response messages for different scenarios - Cleaned up unused methods in github client Closes #141
Perfect! All three issues have been fixed: Summary of Changes
所有修改都已完成,代码现在更加简洁明了,格式化问题也已解决。 |
internal/agent/agent.go
Outdated
} | ||
|
||
// ProcessPRFromReview 从 PR review 批量处理多个 review comments | ||
func (a *Agent) ProcessPRFromReview(ctx context.Context, event *github.PullRequestReviewEvent, command string, args string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/continue ProcessPRFromReview方法应该没被用到?若是请删掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除 ProcessPRFromReview
方法。该方法确实没有被使用,代码库中使用的是 ProcessPRFromReviewWithTriggerUser
方法。
Remove the unused ProcessPRFromReview method from agent.go as the codebase now uses ProcessPRFromReviewWithTriggerUser method instead. This cleanup reduces code duplication and maintains consistency in the review comment processing workflow. Closes #141
internal/agent/agent.go
Outdated
var prompt string | ||
if command == "/continue" { | ||
if args != "" { | ||
prompt = fmt.Sprintf("请根据以下 PR Review 的批量评论和指令继续处理代码:\n\n%s\n\n指令:%s\n\n请一次性处理所有评论中提到的问题,确保保留代码的位置信息,回复要简洁明了。", allComments, args) | ||
} else { | ||
prompt = fmt.Sprintf("请根据以下 PR Review 的批量评论继续处理代码:\n\n%s\n\n请一次性处理所有评论中提到的问题,确保保留代码的位置信息,回复要简洁明了。", allComments) | ||
} | ||
} else { // /fix | ||
if args != "" { | ||
prompt = fmt.Sprintf("请根据以下 PR Review 的批量评论和指令修复代码问题:\n\n%s\n\n指令:%s\n\n请一次性修复所有评论中提到的问题,确保保留代码的位置信息,回复要简洁明了。", allComments, args) | ||
} else { | ||
prompt = fmt.Sprintf("请根据以下 PR Review 的批量评论修复代码问题:\n\n%s\n\n请一次性修复所有评论中提到的问题,确保保留代码的位置信息,回复要简洁明了。", allComments) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/continue 这里的prompt语句中的 "确保保留代码的位置" 是啥意思?如果没必要,也请删掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除四个 prompt 语句中的 "确保保留代码的位置信息" 部分。这个表述确实不够明确且可能是多余的。
Remove "确保保留代码的位置信息" from four prompt statements in batch code review processing. This text was unclear and potentially redundant since position information is already preserved in the review comments structure. Closes #141
/continue 再帮review下本次改动和做下go fmt,不然CI会挂 |
…view scenarios Add support for processing multiple review comments submitted together during code review. When a reviewer submits multiple pending review comments followed by a "/continue" or "/fix" command in the final review submission, the system now: - Detects pull_request_review events with "/continue" or "/fix" prefix - Aggregates related pull_request_review_comment events using review ID - Preserves code line position information for each comment - Provides complete context to AI for comprehensive issue resolution This enhancement allows AI to address all review feedback in a single iteration rather than processing comments individually. Closes #141
Perfect! I've successfully reviewed the code and run Code Review SummaryThe code in
Formatting Results✅ All Go files are now properly formatted
The code is now ready for CI - all formatting issues have been resolved and the code follows proper Go conventions. |
/continue 将修改的各处prompt 内容恢复回去,设计以下几个函数ProcessIssueComment,ContinuePRWithArgs,FixPRWithArgs,ContinuePRFromReviewComment,FixPRFromReviewComment;再顺带做下go fmt |
改动摘要
本次代码改动主要实现了支持Code Review场景下一次性提交多个review comments的功能。当reviewer在GitHub上pending多条review comments,然后在submit review时填写"/continue"或"/fix"开头的信息时,codeagent能够将所有相关的review comments组成完整的上下文给到AI,让AI一次性解决所有问题。
具体改动
internal/github/client.go
GetPullRequestReviews
方法:获取PR的所有reviewsGetReviewComments
方法:获取指定review的所有comments并根据review ID进行过滤internal/webhook/handler.go
HandleWebhook
方法中添加pull_request_review
事件处理分支handlePRReview
方法:处理PR review事件,检测review body中的"/continue"或"/fix"命令,并异步调用agent进行批量处理internal/agent/agent.go
ProcessPRFromReview
方法:批量处理来自PR review的多个comments,构建包含所有评论和位置信息的完整上下文,一次性处理所有问题processReviewOnly
方法:处理只有review body没有具体comments的情况关键特性:
AI 完整输出
编译成功!现在总结我的改动:
改动摘要
本次代码改动主要实现了支持Code Review场景下一次性提交多个review comments的功能。当reviewer在GitHub上pending多条review comments,然后在submit review时填写"/continue"或"/fix"开头的信息时,codeagent能够将所有相关的review comments组成完整的上下文给到AI,让AI一次性解决所有问题。
具体改动
internal/github/client.go
GetPullRequestReviews
方法:获取PR的所有reviewsGetReviewComments
方法:获取指定review的所有comments并根据review ID进行过滤internal/webhook/handler.go
HandleWebhook
方法中添加pull_request_review
事件处理分支handlePRReview
方法:处理PR review事件,检测review body中的"/continue"或"/fix"命令,并异步调用agent进行批量处理internal/agent/agent.go
ProcessPRFromReview
方法:批量处理来自PR review的多个comments,构建包含所有评论和位置信息的完整上下文,一次性处理所有问题processReviewOnly
方法:处理只有review body没有具体comments的情况关键特性:
原始 Prompt
请根据以下 Issue 内容修改代码:
标题:支持Code Review场景下,一次性提交多个review comments的场景
描述:参考场景: qiniu/reviewbot#535 (review)
这种场景下,reviewer 会一次性pending 多条Review comments,然后最后在submit review 时填写 "/continue" 开头的信息,希望codeagent 来修复这些comments。
这种场景下,每条comment都会触发单独的github event 事件(类型是 pull_request_review_comment),"/continue" 也是单独的事件(类型是pull_request_review),所以需要当接收到pull_request_review 事件,并且内容开头包含"/continue" 或"/fix"时,需要将一同触发pull_request_review_comment 事件的内容(可以根据review id 来进行关联),组成完整的上下文给到AI,这样AI一次性解决所有问题。
另外要注意,code Review comments 都是有位置信息的(代码行),这些信息也要给到AI,不能搞丢了。
请直接修改代码,并按照以下格式输出你的分析和操作:
改动摘要
请总结本次代码改动的主要内容。
具体改动
请以简洁的列表形式列出具体改动:
请确保输出格式清晰,便于阅读和理解。