GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Perform consistent diff-informed alert filtering in the action by cklin · Pull Request #2765 · github/codeql-action

Conversation

@cklin

@cklin cklin commented Feb 14, 2025

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cklin
Write pr-diff-range JSON file
77bc2a5
@cklin
cklin marked this pull request as ready for review February 14, 2025 18:04
Copilot AI review requested due to automatic review settings February 14, 2025 18:04
@cklin
cklin requested a review from a team as a code owner February 14, 2025 18:04
@cklin
cklin requested a review from henrymercer February 14, 2025 18:04
@cklin cklin assigned henrymercer Feb 14, 2025
Copilot AI reviewed Feb 14, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/upload-lib.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cklin
cklin force-pushed the cklin/alert-diff-filtering branch from 7004011 to 7e9a076 Compare February 14, 2025 18:11
henrymercer
henrymercer previously approved these changes Feb 17, 2025
View reviewed changes

@henrymercer henrymercer left a comment

Copy link
Copy Markdown
Contributor

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:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/upload-lib.ts
Comment on lines +884 to +890
((range.startLine <= locationStartLine &&
range.endLine >= locationStartLine) ||

@henrymercer henrymercer Feb 17, 2025

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cklin cklin Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/diff-filtering-utils.ts
}
const jsonContents = fs.readFileSync(jsonFilePath, "utf8");
logger.debug(
`Read pr-diff-range JSON file from ${jsonFilePath}:\n${jsonContents}`,

@henrymercer henrymercer Feb 17, 2025

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cklin cklin Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/diff-filtering-utils.ts
const jsonFilePath = getDiffRangesJsonFilePath();
fs.writeFileSync(jsonFilePath, jsonContents);
logger.debug(
`Wrote pr-diff-range JSON file to ${jsonFilePath}:\n${jsonContents}`,

@henrymercer henrymercer Feb 17, 2025

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
henrymercer
henrymercer reviewed Feb 17, 2025
View reviewed changes
Comment thread src/upload-lib.ts Outdated

function filterAlertsByDiffRange(logger: Logger, sarif: SarifFile): SarifFile {
const diffRanges = readDiffRangesJsonFile(logger);
if (!diffRanges) {

@henrymercer henrymercer Feb 17, 2025

Copy link
Copy Markdown
Contributor

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.

Suggested change
if (!diffRanges) {
if (!diffRanges?.length) {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cklin cklin Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cklin
cklin dismissed henrymercer’s stale review via fb0b66d February 19, 2025 14:24
@cklin
cklin force-pushed the cklin/alert-diff-filtering branch from 7e9a076 to fb0b66d Compare February 19, 2025 14:24
cklin added 2 commits February 19, 2025 06:26
@cklin
Filter alerts by pr-diff-range JSON file
dae1626
@cklin
build: refresh js files
f85d8b5
@cklin
cklin force-pushed the cklin/alert-diff-filtering branch from fb0b66d to f85d8b5 Compare February 19, 2025 14:26
@cklin
cklin requested a review from henrymercer February 19, 2025 14:38
henrymercer
henrymercer approved these changes Feb 19, 2025
View reviewed changes

@henrymercer henrymercer left a comment

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cklin
cklin merged commit dbbcbe0 into main Feb 19, 2025
@cklin
cklin deleted the cklin/alert-diff-filtering branch February 19, 2025 18:15
@github-actions github-actions Bot mentioned this pull request Feb 21, 2025
Merge main into releases/v3 #2778
Merged
8 tasks done
@felickz felickz mentioned this pull request Jun 2, 2025
Add support for Diff informed queries advanced-security/monorepo-code-scanning-action#55
Open
1 of 2 tasks
@jbj jbj mentioned this pull request Jul 11, 2025
Support approximate related locations github/codeql#19943
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@henrymercer henrymercer henrymercer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@henrymercer henrymercer

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@cklin @henrymercer
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.