Make jsonFilePath an explicit input to functions in diff-informed/index.ts

This commit is contained in:
Michael B. Gale
2026-11-03 11:01:09 +00:00
parent 3a4f195d36
commit 8c16574468
9 changed files with 81 additions and 49 deletions

29
lib/entry-points.js generated
View File

@@ -181851,7 +181851,7 @@ async function getDiffInformedAnalysisBranches(codeql, features, logger2) {
}
return branches;
}
async function prepareDiffInformedAnalysis(codeql, features, logger2) {
async function prepareDiffInformedAnalysis(logger2, features, codeql, jsonFilePath) {
let branches;
try {
branches = await getDiffInformedAnalysisBranches(codeql, features, logger2);
@@ -181865,7 +181865,7 @@ async function prepareDiffInformedAnalysis(codeql, features, logger2) {
return false;
}
try {
return await computeAndPersistDiffRanges(branches, logger2);
return await computeAndPersistDiffRanges(logger2, jsonFilePath, branches);
} catch (e) {
logger2.warning(
`Failed to compute diff-informed analysis ranges: ${getErrorMessage(e)}`
@@ -181873,17 +181873,15 @@ async function prepareDiffInformedAnalysis(codeql, features, logger2) {
return false;
}
}
function writeDiffRangesJsonFile(logger2, ranges) {
function writeDiffRangesJsonFile(logger2, jsonFilePath, ranges) {
const jsonContents = JSON.stringify(ranges, null, 2);
const jsonFilePath = getDiffRangesJsonFilePath();
fs8.writeFileSync(jsonFilePath, jsonContents);
logger2.debug(
`Wrote pr-diff-range JSON file to ${jsonFilePath}:
${jsonContents}`
);
}
function readDiffRangesJsonFile(logger2) {
const jsonFilePath = getDiffRangesJsonFilePath();
function readDiffRangesJsonFile(logger2, jsonFilePath) {
if (!fs8.existsSync(jsonFilePath)) {
logger2.debug(`Diff ranges JSON file does not exist at ${jsonFilePath}`);
return void 0;
@@ -181923,13 +181921,13 @@ async function getPullRequestEditedDiffRanges(branches, logger2) {
}
return results;
}
async function computeAndPersistDiffRanges(branches, logger2) {
async function computeAndPersistDiffRanges(logger2, jsonFilePath, branches) {
logger2.info("Computing PR diff ranges...");
const ranges = await getPullRequestEditedDiffRanges(branches, logger2);
if (ranges === void 0) {
return false;
}
writeDiffRangesJsonFile(logger2, ranges);
writeDiffRangesJsonFile(logger2, jsonFilePath, ranges);
const distinctFiles = new Set(ranges.map((r) => r.path)).size;
logger2.info(
`Persisted ${ranges.length} diff range(s) across ${distinctFiles} file(s).`
@@ -183066,9 +183064,10 @@ async function initConfig(actionState, inputs) {
);
}
const hasDiffRanges = await prepareDiffInformedAnalysis(
inputs.codeql,
logger2,
inputs.features,
logger2
inputs.codeql,
getDiffRangesJsonFilePath(actionState.env)
);
await applyIncrementalAnalysisSettings(
config,
@@ -186255,7 +186254,10 @@ async function setupDiffInformedQueryRun(logger2, checkoutPath) {
return await withGroupAsync(
"Generating diff range extension pack",
async () => {
const diffRanges = readDiffRangesJsonFile(logger2);
const diffRanges = readDiffRangesJsonFile(
logger2,
getDiffRangesJsonFilePath()
);
if (diffRanges === void 0) {
logger2.info(
"No precomputed diff ranges found; skipping diff-informed analysis stage."
@@ -188758,7 +188760,10 @@ function sanitize(str) {
return (str ?? "_").replace(/[^a-zA-Z0-9_]/g, "_").toLocaleUpperCase();
}
function filterAlertsByDiffRange(logger2, sarifLog) {
const diffRanges = readDiffRangesJsonFile(logger2);
const diffRanges = readDiffRangesJsonFile(
logger2,
getDiffRangesJsonFilePath()
);
if (!diffRanges?.length) {
return sarifLog;
}