Fix: Align PR comment alert count with inline Code Scanning annotations#221
Merged
khyati-crest merged 2 commits intoJun 18, 2026
Merged
Conversation
Test Coverage Reporttotal: (statements) 72.1% Coverage by function |
There was a problem hiding this comment.
Pull request overview
This PR updates the reusable security-scan workflow’s “Post PR Comment with Results” step so the alert count in the PR comment matches the set of findings that GitHub Code Scanning can show as inline annotations (i.e., findings that land on diff-visible lines).
Changes:
- Fetches PR changed files via
github.rest.pulls.listFiles(with pagination) and parses each file’spatchto compute diff-visible line numbers. - Filters SARIF
runs[0].resultsto only results whose(file, startLine)is on a diff-visible line before counting/rendering the PR comment. - Keeps SARIF upload unchanged (still uploads the full SARIF).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Skip '\' sentinel lines (e.g. 'No newline at end of file') in parseDiffLineNumbers to prevent spurious line number misalignment - Explicitly match only '+' and ' ' prefixes instead of any non-'-' line - Use Object.create(null) for diffLines to prevent prototype pollution from filenames like '__proto__' or 'constructor' - Track files with missing patches (large diffs, binary files) as null sentinel and pass their findings through unfiltered to avoid silent under-reporting Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
yiftach-armis
approved these changes
Jun 17, 2026
Collaborator
Author
|
Merged 🎉 Summary of changes:
Tested via: silk-security/Project-Moose#2314 — pointed Follow-up tracked: PPSC-946 — same class of issue in the MCP |
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.
Related Issue
Type of Change
Problem
When the PR Security Scan runs, the general PR comment reports a total alert count that is higher than the number of inline Code Scanning annotations visible in the diff. For example, the comment says "5 total" but only 1 inline annotation appears — the other 4 findings are on lines that were not changed in the PR.
Root cause: The `Post PR Comment with Results` step in `reusable-security-scan.yml` counts `results.length` from the raw SARIF, which includes findings from any line in the changed files. GitHub Code Scanning (via `upload-sarif`) only shows inline annotations for findings whose line falls within the PR diff — so the two counts are computed from different sets, causing a persistent mismatch that confuses users.
Solution
Before counting and rendering findings in the PR comment, fetch the PR's changed file list via the GitHub API (`github.rest.pulls.listFiles`) and build a map of diff-visible line numbers per file. Then filter the SARIF results to only those whose `(file, line)` falls within that map — exactly the same set that GitHub Code Scanning will annotate inline.
Key design decisions:
The `reusable-security-scan.yml` change is purely additive — all existing counting, rendering, and comment update logic is unchanged; it now simply operates on a pre-filtered `results` array instead of `allResults`.
Testing
Automated Tests
Manual Testing
Verified end-to-end via silk-security/Project-Moose#2314 — a test PR in Project-Moose that pointed its `pr-security-scan.yml` at this branch (`@fix/PPSC-781-filter-pr-diff-changes-before-commenting`) instead of `@main`.
Result: All CI checks passed ✅ — lint, tests (4114 passed), and `Security Scan / Armis Security Scan` posted "✅ No issues", confirming the diff-filtering step runs correctly and doesn't break the comment flow for a clean PR.
For a PR with actual findings on unchanged lines, the expected behaviour is:
Reviewer Notes
Checklist