-
Notifications
You must be signed in to change notification settings - Fork 355
Perform consistent diff-informed alert filtering in the action #2765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
7004011
to
7e9a076
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a couple of suggestions:
((range.startLine <= locationStartLine && | ||
range.endLine >= locationStartLine) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if the location's start line isn't within the range but its end line is? If this is intentional, it might be worth adding a comment to make explicit that this case is filtered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I added comments to document the intended behavior of the filtering, by way of referencing the restrictAlertsTo
extensible predicate in QL.
} | ||
const jsonContents = fs.readFileSync(jsonFilePath, "utf8"); | ||
logger.debug( | ||
`Read pr-diff-range JSON file from ${jsonFilePath}:\n${jsonContents}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more robust to log only the first n entries, in case we have a very large PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep the logging as-is for now. Since the JSON file contains only the line ranges, hopefully it will still be manageable even for a very large PR.
const jsonFilePath = getDiffRangesJsonFilePath(); | ||
fs.writeFileSync(jsonFilePath, jsonContents); | ||
logger.debug( | ||
`Wrote pr-diff-range JSON file to ${jsonFilePath}:\n${jsonContents}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/upload-lib.ts
Outdated
|
||
function filterAlertsByDiffRange(logger: Logger, sarif: SarifFile): SarifFile { | ||
const diffRanges = readDiffRangesJsonFile(logger); | ||
if (!diffRanges) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty array is truthy in ECMAScript. In the case that the PR has no changes, it might be better to test diffRanges?.length
instead.
if (!diffRanges) { | |
if (!diffRanges?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Applied.
7e9a076
to
fb0b66d
Compare
fb0b66d
to
f85d8b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional clarifications, LGTM
This PR updates the SARIF upload code path to perform consistent diff-informed alert filtering. With this change, a PR analysis with diff-informed analysis enabled will return only alerts that are within the diff range, regardless of whether the QL queries have been adapted to be diff-informed.