Skip to content

Diff-informed analysis: fix empty PR handling #2818

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Mar 21, 2025

This PR fixes how diff-informed analysis handles empty pull requests.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@cklin cklin marked this pull request as ready for review March 21, 2025 21:41
@Copilot Copilot AI review requested due to automatic review settings March 21, 2025 21:41
@cklin cklin requested a review from a team as a code owner March 21, 2025 21:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes how diff-informed analysis handles empty pull requests to ensure that the absence of added or modified lines does not inadvertently include all alerts.

  • Added a check for empty diff ranges in both JavaScript and TypeScript implementations
  • Replaces an empty diff range with a dummy range that cannot match any alert location

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/analyze.js Adds a check for an empty diff range and sets a dummy range.
src/analyze.ts Adds a similar check and dummy range for empty diff scenarios.

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

Copy link
Contributor

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the descriptive comment 👍

// interprets an empty data extension differently, as an indication that
// all alerts should be included. So we need to specifically set the diff
// range to a non-empty list that cannot match any alert location.
ranges = [{ path: "", startLine: 0, endLine: 0 }];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering whether we have QL logic that looks for locations overlapping with the diff range. But I think that is not possible with this choice of range.

This looks right as long as we don't try to check the path against actual paths in the source archive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When start line and end line are both 0, the QL logic that matches location overlapping with the diff range is a simple join on the absolute path. Since an absolute path in a PR diff cannot be empty, such a join should very efficiently discard all valid potential alert locations.

@cklin cklin merged commit e0ea141 into main Mar 21, 2025
533 checks passed
@cklin cklin deleted the cklin/empty-pr-diff-range branch March 21, 2025 23:04
@github-actions github-actions bot mentioned this pull request Mar 24, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants