Move getDiffRangesJsonFilePath to diff-informed/index.ts

This commit is contained in:
Michael B. Gale
2026-11-04 15:00:19 +00:00
parent 8c16574468
commit c29d405e42
10 changed files with 795 additions and 776 deletions

1494
lib/entry-points.js generated

File diff suppressed because it is too large Load Diff

View File

@@ -78,16 +78,6 @@ export function getTemporaryDirectory(env: ReadOnlyEnv = getEnv()): string {
);
}
/** The filename used to persist PR diff ranges. */
const PR_DIFF_RANGE_JSON_FILENAME = "pr-diff-range.json";
/**
* Gets the full path of the file used to persist PR diff ranges.
*/
export function getDiffRangesJsonFilePath(env: Env = getEnv()): string {
return path.join(getTemporaryDirectory(env), PR_DIFF_RANGE_JSON_FILENAME);
}
export function getActionVersion(): string {
return __CODEQL_ACTION_VERSION__;
}

View File

@@ -6,10 +6,7 @@ import * as io from "@actions/io";
import * as yaml from "js-yaml";
import type { ActionState } from "./action-common";
import {
getDiffRangesJsonFilePath,
getTemporaryDirectory,
} from "./actions-util";
import { getTemporaryDirectory } from "./actions-util";
import * as analyses from "./analyses";
import { setupCppAutobuild } from "./autobuild";
import { type CodeQL } from "./codeql";
@@ -21,7 +18,11 @@ import {
getJavaTempDependencyDir,
} from "./dependency-caching";
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
import { type DiffThunkRange, readDiffRangesJsonFile } from "./diff-informed";
import {
type DiffThunkRange,
getDiffRangesJsonFilePath,
readDiffRangesJsonFile,
} from "./diff-informed";
import { EnvVar } from "./environment";
import { FeatureEnablement, Feature } from "./feature-flags";
import { getGitRoot } from "./git-utils";

View File

@@ -7,7 +7,6 @@ import * as yaml from "js-yaml";
import { ActionState } from "./action-common";
import {
getActionVersion,
getDiffRangesJsonFilePath,
getOptionalInput,
isAnalyzingPullRequest,
isDefaultSetup,
@@ -49,7 +48,10 @@ import {
addNoLanguageDiagnostic,
makeTelemetryDiagnostic,
} from "./diagnostics";
import { prepareDiffInformedAnalysis } from "./diff-informed";
import {
getDiffRangesJsonFilePath,
prepareDiffInformedAnalysis,
} from "./diff-informed";
import { EnvVar, exportEnvVar, getEnv } from "./environment";
import * as errorMessages from "./error-messages";
import { Feature, FeatureEnablement, FeatureWithoutCLI } from "./feature-flags";

View File

@@ -23,6 +23,7 @@ import {
getDiffInformedAnalysisBranches,
prepareDiffInformedAnalysis,
exportedForTesting,
getDiffRangesJsonFilePath,
} from ".";
setupTests(test);
@@ -197,7 +198,7 @@ test.serial(
logger,
features,
codeql,
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
getDiffRangesJsonFilePath(getEnv()),
);
t.false(result);
@@ -228,7 +229,7 @@ test.serial(
logger,
features,
codeql,
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
getDiffRangesJsonFilePath(getEnv()),
);
t.false(result);
@@ -266,7 +267,7 @@ test.serial(
logger,
features,
codeql,
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
getDiffRangesJsonFilePath(getEnv()),
);
t.true(result);
@@ -304,7 +305,7 @@ test.serial(
logger,
features,
codeql,
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
getDiffRangesJsonFilePath(getEnv()),
);
t.false(result);

View File

@@ -1,14 +1,30 @@
import * as fs from "fs";
import path from "path";
import * as actionsUtil from "../actions-util";
import type { PullRequestBranches } from "../actions-util";
import { getApiClient, getGitHubVersion } from "../api-client";
import type { CodeQL } from "../codeql";
import { Feature, FeatureEnablement } from "../feature-flags";
import { type Env, getEnv } from "../environment";
import type { FeatureEnablement } from "../feature-flags";
import { Feature } from "../feature-flags/features";
import { Logger } from "../logging";
import { getRepositoryNwoFromEnv } from "../repository";
import { getErrorMessage, GitHubVariant, satisfiesGHESVersion } from "../util";
/** The filename used to persist PR diff ranges. */
const PR_DIFF_RANGE_JSON_FILENAME = "pr-diff-range.json";
/**
* Gets the full path of the file used to persist PR diff ranges.
*/
export function getDiffRangesJsonFilePath(env: Env = getEnv()): string {
return path.join(
actionsUtil.getTemporaryDirectory(env),
PR_DIFF_RANGE_JSON_FILENAME,
);
}
/**
* This interface is an abbreviated version of the file diff object returned by
* the GitHub API.

View File

@@ -5,6 +5,7 @@ import test from "ava";
import * as sinon from "sinon";
import * as actionsUtil from "../actions-util";
import * as diffInformed from "../diff-informed";
import * as gitUtils from "../git-utils";
import {
createTestConfig,
@@ -60,7 +61,7 @@ test.serial(
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
sinon
.stub(actionsUtil, "getDiffRangesJsonFilePath")
.stub(diffInformed, "getDiffRangesJsonFilePath")
.returns(diffRangeFilePath);
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
const changesFilePath = await writeOverlayChangesFile(
@@ -126,7 +127,7 @@ test.serial(
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
sinon
.stub(actionsUtil, "getDiffRangesJsonFilePath")
.stub(diffInformed, "getDiffRangesJsonFilePath")
.returns(diffRangeFilePath);
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
@@ -196,7 +197,7 @@ test.serial(
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
sinon
.stub(actionsUtil, "getDiffRangesJsonFilePath")
.stub(diffInformed, "getDiffRangesJsonFilePath")
.returns(diffRangeFilePath);
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
@@ -259,7 +260,7 @@ test.serial(
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
sinon
.stub(actionsUtil, "getDiffRangesJsonFilePath")
.stub(diffInformed, "getDiffRangesJsonFilePath")
.returns(diffRangeFilePath);
// getGitRoot returns the repo root (parent of sourceRoot)
sinon.stub(gitUtils, "getGitRoot").resolves(repoRoot);

View File

@@ -1,9 +1,9 @@
import * as fs from "fs";
import * as path from "path";
import * as actionsUtil from "../actions-util";
import { getOptionalInput, getTemporaryDirectory } from "../actions-util";
import { type Config } from "../config-utils";
import { getDiffRangesJsonFilePath } from "../diff-informed";
import { getFileOidsUnderPath, getGitRoot } from "../git-utils";
import { Logger } from "../logging";
import { getBaseDatabaseOidsFilePath } from "../util";
@@ -135,7 +135,7 @@ async function getDiffRangeFilePaths(
sourceRoot: string,
logger: Logger,
): Promise<string[]> {
const jsonFilePath = actionsUtil.getDiffRangesJsonFilePath();
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs.existsSync(jsonFilePath)) {
logger.debug(

View File

@@ -6,7 +6,6 @@ import { HTTPError } from "@actions/tool-cache";
import test from "ava";
import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import * as analyses from "./analyses";
import { AnalysisKind, CodeQuality, CodeScanning } from "./analyses";
import * as api from "./api-client";
@@ -1075,7 +1074,7 @@ function runFilterAlertsByDiffRange(
logger: Logger = new RecordingLogger(),
): Partial<sarif.Log> {
sinon.stub(diffUtils, "readDiffRangesJsonFile").returns(diffRanges);
sinon.stub(actionsUtil, "getDiffRangesJsonFilePath").returns("");
sinon.stub(diffUtils, "getDiffRangesJsonFilePath").returns("");
return uploadLib.filterAlertsByDiffRange(logger, input);
}

View File

@@ -13,7 +13,10 @@ import * as api from "./api-client";
import { getGitHubVersion, wrapApiConfigurationError } from "./api-client";
import { CodeQL, getCodeQL } from "./codeql";
import type { ActionConfig } from "./config/action-config";
import { readDiffRangesJsonFile } from "./diff-informed";
import {
getDiffRangesJsonFilePath,
readDiffRangesJsonFile,
} from "./diff-informed";
import { ActionsEnvVars, EnvVar, exportEnvVar } from "./environment";
import { FeatureEnablement } from "./feature-flags";
import * as fingerprints from "./fingerprints";
@@ -1081,7 +1084,7 @@ export function filterAlertsByDiffRange(
): Partial<sarif.Log> {
const diffRanges = readDiffRangesJsonFile(
logger,
actionsUtil.getDiffRangesJsonFilePath(),
getDiffRangesJsonFilePath(),
);
if (!diffRanges?.length) {
return sarifLog;