feat: comment on an issue whose fix reaches beyond the pull request diff - #151
Merged
Conversation
An issue was commented on only when the diff showed every line it spans, because GitHub rejects a comment anchored outside the diff. A formatter that reformats a whole statement because one of its lines changed reports a range reaching past the three context lines the diff carries around that change, so such an issue failed the step without any comment explaining it. The comment is now anchored on the run of lines that the diff does show around an added line of the range, which is the widest anchor GitHub accepts. The fix of an issue reaching beyond that anchor is rendered as a plain code block naming the lines it covers rather than as a suggestion, since applying it in one click would rewrite lines the pull request does not show. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🎉 This PR is included in version 5.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
What
An issue was commented on only when the pull request diff showed every line it spans, since GitHub rejects a comment anchored outside the diff. That made the action fail a step without any comment explaining why.
Now the comment is anchored on the run of lines the diff does show around an added line of the range — the widest anchor GitHub accepts — and a fix reaching beyond that anchor is rendered as a plain code block with a note naming the lines it covers, instead of a suggestion that would rewrite lines the pull request does not show.
Why
Found on a real
clang-formatrun (winagent run 11519055):IoCreateFileEx(...)call;git-clang-formatcorrectly passed--lines=877:877, but clang-format's smallest unit is the whole statement, so it re-laid-out lines 868–883;isNewIssue(some line added) kept the issue → the step failed.isCommentableIssue(every line in the diff) rejected it → no comment at all. This closes that gap: sinceisNewIssueguarantees at least one added line, an anchor always exists.Implementation
isCommentableIssueis replaced bygetCommentAnchor, which returns the normalized path, the anchored range and whether it ispartial, orundefinedwhen the diff adds none of the issue's lines. It grows the anchor from the first added line outwards while the neighbouring lines are in the diff, staying inside both the issue range and a single hunk.buildCommentBodytakes apartialflag and renders the fix as a plain fence plus the note instead of asuggestion.addCommentsuses the anchor forpath/line/start_line, so the comment lands on lines GitHub accepts.Testing
getCommentAnchor: full range, truncated range, path relativization, and the cases that anchor nothing (no added line, unknown file, missing path/line, end line before start line).fixBeyondDiffsuite mirroring the winagent case exactly — issue 868–883 against a@@ -874,7 +874,7 @@hunk — asserting the874–880anchor, the plain-fence body with the note, and that a fully shown fix still renders as a suggestion.clang-formatdiff (reproduced locally byte-identical to the run's SARIF) plus the real PR diff now yield an anchor of874–880and a comment carrying the full 15-line replacement, where the run produced nothing.