Skip to content

Conversation

alexet
Copy link
Contributor

@alexet alexet commented Oct 9, 2025

This includes the PR diff in the overlay changes so that any "overlay informed analysis" runs in a detailed way on those files..

This requires writing pr-diff-range.json in init and reading inside analyse.

A minor change is that for an empty PR diff, a dummy entry is not written to pr-diff-range.json. analyse still adds it to the generated pack, but it isn't used by `upload``.

I am assuming that mixing and matching init and analyse from different action versions is not supported.

Risk assessment

  • High risk: Changes are not fully under feature flags, have limited visibility and/or cannot be tested outside of production.

Which use cases does this change impact?

This affects all cases where diff-informed may apply:

  • Advanced setup - Impacts users who have custom workflows.
  • Default setup - Impacts users who use default setup.
  • Code Scanning - Impacts Code Scanning (i.e. analysis-kinds: code-scanning).
  • GHES - Impacts GitHub Enterprise Server.

How did/will you validate this change?

  • Test repository - This change will be tested on a test repository before merging. (TODO: Do this)
  • Unit tests - I have run the existing unit tests but they don'#t cover much here.
  • End-to-end tests -

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Rollback - Rollback is the primary strategy as feature flagging this change is tricky.
  • Feature flags - In an emergency (or if this only affects a few repos) we can switch off diff-informed.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Dashboards - I will watch the diff informed dashboard to check it still is positive.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

@alexet alexet force-pushed the alexet/diff-implies-overlay branch from ab7a163 to f030ca3 Compare October 9, 2025 20:05
@alexet alexet force-pushed the alexet/diff-implies-overlay branch from 44ed913 to 5a8e345 Compare October 10, 2025 13:26
@alexet alexet changed the title Make the overlay changed files always include the DIFF Make the overlay changed files always include the diff Oct 10, 2025
@alexet alexet marked this pull request as ready for review October 10, 2025 18:10
@alexet alexet requested a review from a team as a code owner October 10, 2025 18:10
@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 18:10
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 integrates diff-informed analysis into overlay mode by computing PR diff ranges during init and including changed files from the diff in overlay analysis. This ensures that overlay analysis always processes files with at least one edited range, improving the coverage of diff-informed analysis.

Key changes:

  • Moves diff range computation from analyze to init step to enable early persistence and reuse
  • Augments overlay changed files with files from PR diff ranges
  • Refactors diff-informed analysis logic to use precomputed ranges instead of computing them during analyze

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/overlay-database-utils.ts Enhanced to accept PR diff changed files and include them in overlay analysis
src/init-action.ts Added early computation and persistence of diff ranges with new helper function
src/diff-informed-analysis-utils.ts Moved diff computation logic from analyze.ts and added export functions
src/analyze.ts Refactored to use precomputed diff ranges instead of computing them inline
src/codeql.ts Updated interface to accept PR diff changed files parameter
Comments suppressed due to low confidence (1)

src/diff-informed-analysis-utils.ts:1

  • The replaceAll method may not be available in older Node.js versions. Consider using replace with a global regex for better compatibility: .replace(new RegExp('\\' + path.sep, 'g'), '/')
import * as fs from "fs";

}
if (extraAddedCount > 0) {
logger.debug(
`Added ${extraAddedCount} file(s) from PR diff ranges into overlay: ${changedFiles.slice(-extraAddedCount).join(", ")}`,
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The slice operation on changedFiles array could be inefficient for large arrays. Consider tracking the added files separately to avoid the slice operation on potentially large arrays.

Copilot uses AI. Check for mistakes.

return undefined;
}
writeDiffRangesJsonFile(logger, ranges);
const distinctFiles = new Set(ranges.map((r) => r.path));
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

Creating a Set from mapped array could be optimized by using a for loop to avoid creating an intermediate array, especially for large numbers of ranges.

Suggested change
const distinctFiles = new Set(ranges.map((r) => r.path));
const distinctFiles = new Set<string>();
for (const r of ranges) {
distinctFiles.add(r.path);
}

Copilot uses AI. Check for mistakes.

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.

1 participant