fix(code-scan): route file-only findings to general comments#9556
fix(code-scan): route file-only findings to general comments#9556serhiizghama wants to merge 2 commits into
Conversation
When line is null, GitHub rejects inline review comments that have a path but no line number. File-only findings must go to generalComments instead of lineComments so the fallback posting path succeeds.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3b322a40e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const lineComments = sortedComments.filter((c) => c.file && c.line != null && c.finding); | ||
| const generalComments = sortedComments.filter( | ||
| (c) => !c.file && c.finding && c.severity !== CodeScanSeverity.NONE, | ||
| (c) => (!c.file || c.line == null) && c.finding && c.severity !== CodeScanSeverity.NONE, |
There was a problem hiding this comment.
Include file paths for file-only general comments
When a finding has file set but line: null, this predicate now sends it through postGeneralComments(), whose body is built by buildCommentBody(comment) and never includes comment.file; inline comments get their location from GitHub, but these issue comments do not. For file-scoped findings whose finding text does not repeat the path (the schema carries the path separately, and SARIF/CLI output also render it separately), the PR comment is posted without the affected file, making the result hard to act on. Consider preserving the file path in the general-comment body for this newly routed case.
Useful? React with 👍 / 👎.
Problem
The fallback PR-posting path in the code-scan action drops comments when the scan server returns file-scoped findings with
line: null.prepareComments()insrc/codeScan/util/github.tsclassifies every comment that has afilefield as alineComment. WhentoReviewComment()maps such a comment forpulls.createReview(),comment.linebecomesundefined. GitHub rejects inline review comments that have apathbut no valid line number, so the entire fallback post silently fails.Traced in issue #9422:
CommentSchema(and SARIF emitter) explicitly allowline: nullfor file-only findingsprepareCommentssplit was treatingc.file && c.findingas sufficient for a line commentf6af1ecbut the rootprepareCommentshelper was not updatedSolution
Tighten the
lineCommentspredicate to require a non-nullline:Widen
generalCommentsto catch file-only findings:File-only findings now go through
issues.createComment()as general PR comments, which accepts any finding without a line location.Testing
Added a test case to
test/codeScans/util/github.test.tsthat verifies a comment withfileset andline: nullends up ingeneralComments, notlineComments.All existing tests continue to pass (
npx vitest run test/codeScans/util/github.test.ts).