fix: validate inline review comment lines against diff hunks - #1348
Merged
Conversation
The post-review script was failing with GitHub 422 errors when the review agent placed inline comments on lines that exist in the file but fall outside any diff hunk. The existing validation only checked whether the file was in the PR diff, not whether the specific line was within a diff hunk. Add ListPullRequestFileDiffs to the forge interface which returns the unified diff patch alongside each file path. Parse hunk headers to extract valid line ranges and filter out comments targeting lines outside those ranges before submitting the review. Signed-off-by: Wayne Sun <gsun@redhat.com>
Site previewPreview: https://43c43f2c-site.fullsend-ai.workers.dev Commit: |
ReviewFindingsLow
All seven review dimensions evaluated. The hunk-header parsing ( Previous runReviewFindingsNo findings. |
Files with empty patches (binary, renamed-only, truncated large diffs) had all inline comments silently dropped because parseDiffLineRanges returned nil and lineInHunks always returned false. Skip line-level filtering when hunk data is unavailable. Also adds a strings.HasPrefix fast-path to skip regex evaluation on non-hunk-header lines. Signed-off-by: Wayne Sun <gsun@redhat.com>
This was referenced May 22, 2026
4 tasks
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ListPullRequestFileDiffsto the forge interface to return unified diff patches alongside file pathsparseDiffLineRangesto extract valid new-side line ranges from@@ -a,b +c,d @@hunk headersfindingsToReviewCommentsto filter by both file presence and line-in-hunk, with separate warning countsTest plan
TestParseDiffLineRanges— single hunk, multiple hunks, new file, deletion-only, omitted size, empty patch, mixedTestFindingsToReviewComments— no filtering when diffHunks is nilTestFindingsToReviewComments_FiltersByDiffHunks— file not in diff, line outside hunk, line inside hunkTestSubmitFormalReview_FiltersByPRFileDiffs— end-to-end with fake client and patchesTestSubmitFormalReview_ListPRFileDiffsErrorFallsBack— graceful fallback on API errorTestSubmitFormalReview_EmptyPRFileDiffListFallsBack— graceful fallback on empty listTestListPullRequestFileDiffs— GitHub client correctly extracts path and patchgo test ./internal/cli/... ./internal/forge/...all passgo vetclean