mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 09:14:58 +00:00
feat: always include files from diff in overlay changed files
This commit is contained in:
73
lib/upload-lib.js
generated
73
lib/upload-lib.js
generated
@@ -100540,8 +100540,8 @@ var require_follow_redirects = __commonJS({
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
function resolveUrl(relative2, base) {
|
||||
return useNativeURL ? new URL2(relative2, base) : parseUrl2(url2.resolve(base, relative2));
|
||||
function resolveUrl(relative3, base) {
|
||||
return useNativeURL ? new URL2(relative3, base) : parseUrl2(url2.resolve(base, relative3));
|
||||
}
|
||||
function validateUrl(input) {
|
||||
if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
|
||||
@@ -107360,6 +107360,18 @@ var decodeGitFilePath = function(filePath) {
|
||||
}
|
||||
return filePath;
|
||||
};
|
||||
var getGitRoot = async function(sourceRoot) {
|
||||
try {
|
||||
const stdout = await runGitCommand(
|
||||
sourceRoot,
|
||||
["rev-parse", "--show-toplevel"],
|
||||
`Cannot find Git repository root from the source root ${sourceRoot}.`
|
||||
);
|
||||
return stdout.trim();
|
||||
} catch {
|
||||
return void 0;
|
||||
}
|
||||
};
|
||||
var getFileOidsUnderPath = async function(basePath) {
|
||||
const stdout = await runGitCommand(
|
||||
basePath,
|
||||
@@ -107482,10 +107494,12 @@ async function readBaseDatabaseOidsFile(config, logger) {
|
||||
async function writeOverlayChangesFile(config, sourceRoot, logger) {
|
||||
const baseFileOids = await readBaseDatabaseOidsFile(config, logger);
|
||||
const overlayFileOids = await getFileOidsUnderPath(sourceRoot);
|
||||
const changedFiles = computeChangedFiles(baseFileOids, overlayFileOids);
|
||||
const oidChangedFiles = computeChangedFiles(baseFileOids, overlayFileOids);
|
||||
logger.info(
|
||||
`Found ${changedFiles.length} changed file(s) under ${sourceRoot}.`
|
||||
`Found ${oidChangedFiles.length} changed file(s) under ${sourceRoot} from OID comparison.`
|
||||
);
|
||||
const diffRangeFiles = await getDiffRangeFilePaths(sourceRoot, logger);
|
||||
const changedFiles = [.../* @__PURE__ */ new Set([...oidChangedFiles, ...diffRangeFiles])];
|
||||
const changedFilesJson = JSON.stringify({ changes: changedFiles });
|
||||
const overlayChangesFile = path4.join(
|
||||
getTemporaryDirectory(),
|
||||
@@ -107511,6 +107525,48 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
async function getDiffRangeFilePaths(sourceRoot, logger) {
|
||||
const jsonFilePath = path4.join(getTemporaryDirectory(), "pr-diff-range.json");
|
||||
if (!fs3.existsSync(jsonFilePath)) {
|
||||
return [];
|
||||
}
|
||||
let diffRanges;
|
||||
try {
|
||||
diffRanges = JSON.parse(fs3.readFileSync(jsonFilePath, "utf8"));
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
`Failed to parse diff ranges JSON file at ${jsonFilePath}: ${e}`
|
||||
);
|
||||
return [];
|
||||
}
|
||||
logger.debug(
|
||||
`Read ${diffRanges.length} diff range(s) from ${jsonFilePath} for overlay changes.`
|
||||
);
|
||||
const repoRelativePaths = [...new Set(diffRanges.map((r) => r.path))];
|
||||
const repoRoot = await getGitRoot(sourceRoot);
|
||||
if (repoRoot === void 0) {
|
||||
logger.warning(
|
||||
"Cannot determine git root; returning diff range paths as-is."
|
||||
);
|
||||
return repoRelativePaths;
|
||||
}
|
||||
const sourceRootRelPrefix = path4.relative(repoRoot, sourceRoot).replaceAll(path4.sep, "/");
|
||||
if (sourceRootRelPrefix === "") {
|
||||
return repoRelativePaths;
|
||||
}
|
||||
const prefixWithSlash = `${sourceRootRelPrefix}/`;
|
||||
const result = [];
|
||||
for (const p of repoRelativePaths) {
|
||||
if (p.startsWith(prefixWithSlash)) {
|
||||
result.push(p.slice(prefixWithSlash.length));
|
||||
} else {
|
||||
logger.debug(
|
||||
`Skipping diff range path "${p}" (not under source root "${sourceRootRelPrefix}").`
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// src/tools-features.ts
|
||||
var semver4 = __toESM(require_semver2());
|
||||
@@ -107750,7 +107806,14 @@ function readDiffRangesJsonFile(logger) {
|
||||
`Read pr-diff-range JSON file from ${jsonFilePath}:
|
||||
${jsonContents}`
|
||||
);
|
||||
return JSON.parse(jsonContents);
|
||||
try {
|
||||
return JSON.parse(jsonContents);
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
`Failed to parse diff ranges JSON file at ${jsonFilePath}: ${e}`
|
||||
);
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
|
||||
// src/overlay/status.ts
|
||||
|
||||
Reference in New Issue
Block a user