feat: batch inline comments into a single PR review submission#1147
feat: batch inline comments into a single PR review submission#1147hashwnath wants to merge 1 commit intoanthropics:mainfrom
Conversation
Instead of posting each inline comment as an individual API call (which generates N separate notifications), submit all comments together via the GitHub Pull Request Reviews API. This produces a single notification and a cohesive review entry in the PR timeline. Falls back to individual comment posting if the batch review fails (e.g. when a comment targets an invalid path or line that the review API rejects). Fixes anthropics#1049
suramkavyasree
left a comment
There was a problem hiding this comment.
❌ Code Review: Changes Requested
The code effectively consolidates inline comments into a single review submission, reducing notification noise and improving review coherence. However, there are high-priority issues such as missing type hints, improper logging, and a bare except block that need addressing.
Issue Summary
| Severity | Count |
|---|---|
| 3 | |
| 🔵 Low | 1 |
Automated review by Code Review Agent
| /** | ||
| * Submit all comments as a single GitHub Pull Request Review. This produces | ||
| * one notification instead of N separate notifications for each comment. | ||
| * Falls back to posting individual comments if the batch review fails (e.g. |
There was a problem hiding this comment.
The function postCommentsAsReview lacks type hints for its parameters and return value.
Why this matters: Type hints improve code readability and help with static analysis, making it easier to understand and maintain the code.
Suggested fix:
Add type hints for all parameters and the return value of the function.| } = { | ||
| path: c.path, | ||
| body: c.body, | ||
| side: c.side || "RIGHT", |
There was a problem hiding this comment.
The code uses console.log for logging, which is not suitable for production environments.
Why this matters: Using a structured logger like structlog provides better logging capabilities, such as log levels, structured data, and better integration with logging systems.
Suggested fix:
Replace console.log with structlog logger.| side: c.side || "RIGHT", | ||
| }; | ||
| if (c.startLine) { | ||
| comment.start_line = c.startLine; |
There was a problem hiding this comment.
The catch block uses a bare exception handling pattern, which can swallow all exceptions, including system-exiting ones.
Why this matters: Using a bare except can hide bugs and make debugging difficult. It's important to catch specific exceptions to handle known error conditions.
Suggested fix:
Catch specific exceptions instead of using a bare except.| /** | ||
| * Submit all comments as a single GitHub Pull Request Review. This produces | ||
| * one notification instead of N separate notifications for each comment. | ||
| * Falls back to posting individual comments if the batch review fails (e.g. |
There was a problem hiding this comment.
🔵 LOW: Missing Google-style docstring for public function
The function postCommentsAsReview lacks a Google-style docstring with Args, Returns, and Raises sections.
Why this matters: Comprehensive docstrings provide clear documentation for function usage, expected inputs, outputs, and potential exceptions.
Suggested fix:
Add a Google-style docstring with Args, Returns, and Raises sections.|
This looks amazing and highly needed! Would love to see this merged. |
|
Same here !!! |
Fixes #1049
Problem
The post-processing step posts each buffered inline comment as an individual
createReviewCommentAPI call. For a review with N inline comments, this generates N separate email notifications and N disconnected entries in the PR timeline — noisy and hard to review as a whole.Solution
Replace the individual comment loop with a single
createReview()API call that submits all inline comments together as one cohesive PR review withevent: "COMMENT". This:Changes
src/entrypoints/post-buffered-inline-comments.ts: AddedpostCommentsAsReview()that maps buffered comments to thepulls.createReviewAPI format and submits them as a single review. The existingpostComment()function is retained as the fallback path.Testing
postComment()fallback ensures no regressions — if batch submission fails for any reason, comments are posted individually as before