Skip to content

Commit c29d405

Browse files
committed
Move getDiffRangesJsonFilePath to diff-informed/index.ts
1 parent 8c16574 commit c29d405

10 files changed

Lines changed: 795 additions & 776 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 750 additions & 744 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/actions-util.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ export function getTemporaryDirectory(env: ReadOnlyEnv = getEnv()): string {
7878
);
7979
}
8080

81-
/** The filename used to persist PR diff ranges. */
82-
const PR_DIFF_RANGE_JSON_FILENAME = "pr-diff-range.json";
83-
84-
/**
85-
* Gets the full path of the file used to persist PR diff ranges.
86-
*/
87-
export function getDiffRangesJsonFilePath(env: Env = getEnv()): string {
88-
return path.join(getTemporaryDirectory(env), PR_DIFF_RANGE_JSON_FILENAME);
89-
}
90-
9181
export function getActionVersion(): string {
9282
return __CODEQL_ACTION_VERSION__;
9383
}

‎src/analyze.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import * as io from "@actions/io";
66
import * as yaml from "js-yaml";
77

88
import type { ActionState } from "./action-common";
9-
import {
10-
getDiffRangesJsonFilePath,
11-
getTemporaryDirectory,
12-
} from "./actions-util";
9+
import { getTemporaryDirectory } from "./actions-util";
1310
import * as analyses from "./analyses";
1411
import { setupCppAutobuild } from "./autobuild";
1512
import { type CodeQL } from "./codeql";
@@ -21,7 +18,11 @@ import {
2118
getJavaTempDependencyDir,
2219
} from "./dependency-caching";
2320
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
24-
import { type DiffThunkRange, readDiffRangesJsonFile } from "./diff-informed";
21+
import {
22+
type DiffThunkRange,
23+
getDiffRangesJsonFilePath,
24+
readDiffRangesJsonFile,
25+
} from "./diff-informed";
2526
import { EnvVar } from "./environment";
2627
import { FeatureEnablement, Feature } from "./feature-flags";
2728
import { getGitRoot } from "./git-utils";

‎src/config-utils.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as yaml from "js-yaml";
77
import { ActionState } from "./action-common";
88
import {
99
getActionVersion,
10-
getDiffRangesJsonFilePath,
1110
getOptionalInput,
1211
isAnalyzingPullRequest,
1312
isDefaultSetup,
@@ -49,7 +48,10 @@ import {
4948
addNoLanguageDiagnostic,
5049
makeTelemetryDiagnostic,
5150
} from "./diagnostics";
52-
import { prepareDiffInformedAnalysis } from "./diff-informed";
51+
import {
52+
getDiffRangesJsonFilePath,
53+
prepareDiffInformedAnalysis,
54+
} from "./diff-informed";
5355
import { EnvVar, exportEnvVar, getEnv } from "./environment";
5456
import * as errorMessages from "./error-messages";
5557
import { Feature, FeatureEnablement, FeatureWithoutCLI } from "./feature-flags";

‎src/diff-informed/index.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
getDiffInformedAnalysisBranches,
2424
prepareDiffInformedAnalysis,
2525
exportedForTesting,
26+
getDiffRangesJsonFilePath,
2627
} from ".";
2728

2829
setupTests(test);
@@ -197,7 +198,7 @@ test.serial(
197198
logger,
198199
features,
199200
codeql,
200-
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
201+
getDiffRangesJsonFilePath(getEnv()),
201202
);
202203

203204
t.false(result);
@@ -228,7 +229,7 @@ test.serial(
228229
logger,
229230
features,
230231
codeql,
231-
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
232+
getDiffRangesJsonFilePath(getEnv()),
232233
);
233234

234235
t.false(result);
@@ -266,7 +267,7 @@ test.serial(
266267
logger,
267268
features,
268269
codeql,
269-
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
270+
getDiffRangesJsonFilePath(getEnv()),
270271
);
271272

272273
t.true(result);
@@ -304,7 +305,7 @@ test.serial(
304305
logger,
305306
features,
306307
codeql,
307-
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
308+
getDiffRangesJsonFilePath(getEnv()),
308309
);
309310

310311
t.false(result);

‎src/diff-informed/index.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
import * as fs from "fs";
2+
import path from "path";
23

34
import * as actionsUtil from "../actions-util";
45
import type { PullRequestBranches } from "../actions-util";
56
import { getApiClient, getGitHubVersion } from "../api-client";
67
import type { CodeQL } from "../codeql";
7-
import { Feature, FeatureEnablement } from "../feature-flags";
8+
import { type Env, getEnv } from "../environment";
9+
import type { FeatureEnablement } from "../feature-flags";
10+
import { Feature } from "../feature-flags/features";
811
import { Logger } from "../logging";
912
import { getRepositoryNwoFromEnv } from "../repository";
1013
import { getErrorMessage, GitHubVariant, satisfiesGHESVersion } from "../util";
1114

15+
/** The filename used to persist PR diff ranges. */
16+
const PR_DIFF_RANGE_JSON_FILENAME = "pr-diff-range.json";
17+
18+
/**
19+
* Gets the full path of the file used to persist PR diff ranges.
20+
*/
21+
export function getDiffRangesJsonFilePath(env: Env = getEnv()): string {
22+
return path.join(
23+
actionsUtil.getTemporaryDirectory(env),
24+
PR_DIFF_RANGE_JSON_FILENAME,
25+
);
26+
}
27+
1228
/**
1329
* This interface is an abbreviated version of the file diff object returned by
1430
* the GitHub API.

‎src/overlay/index.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import test from "ava";
55
import * as sinon from "sinon";
66

77
import * as actionsUtil from "../actions-util";
8+
import * as diffInformed from "../diff-informed";
89
import * as gitUtils from "../git-utils";
910
import {
1011
createTestConfig,
@@ -60,7 +61,7 @@ test.serial(
6061
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
6162
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
6263
sinon
63-
.stub(actionsUtil, "getDiffRangesJsonFilePath")
64+
.stub(diffInformed, "getDiffRangesJsonFilePath")
6465
.returns(diffRangeFilePath);
6566
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
6667
const changesFilePath = await writeOverlayChangesFile(
@@ -126,7 +127,7 @@ test.serial(
126127
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
127128
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
128129
sinon
129-
.stub(actionsUtil, "getDiffRangesJsonFilePath")
130+
.stub(diffInformed, "getDiffRangesJsonFilePath")
130131
.returns(diffRangeFilePath);
131132
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
132133

@@ -196,7 +197,7 @@ test.serial(
196197
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
197198
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
198199
sinon
199-
.stub(actionsUtil, "getDiffRangesJsonFilePath")
200+
.stub(diffInformed, "getDiffRangesJsonFilePath")
200201
.returns(diffRangeFilePath);
201202
sinon.stub(gitUtils, "getGitRoot").resolves(sourceRoot);
202203

@@ -259,7 +260,7 @@ test.serial(
259260
const diffRangeFilePath = path.join(tempDir, "pr-diff-range.json");
260261
sinon.stub(actionsUtil, "getTemporaryDirectory").returns(tempDir);
261262
sinon
262-
.stub(actionsUtil, "getDiffRangesJsonFilePath")
263+
.stub(diffInformed, "getDiffRangesJsonFilePath")
263264
.returns(diffRangeFilePath);
264265
// getGitRoot returns the repo root (parent of sourceRoot)
265266
sinon.stub(gitUtils, "getGitRoot").resolves(repoRoot);

‎src/overlay/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from "fs";
22
import * as path from "path";
33

4-
import * as actionsUtil from "../actions-util";
54
import { getOptionalInput, getTemporaryDirectory } from "../actions-util";
65
import { type Config } from "../config-utils";
6+
import { getDiffRangesJsonFilePath } from "../diff-informed";
77
import { getFileOidsUnderPath, getGitRoot } from "../git-utils";
88
import { Logger } from "../logging";
99
import { getBaseDatabaseOidsFilePath } from "../util";
@@ -135,7 +135,7 @@ async function getDiffRangeFilePaths(
135135
sourceRoot: string,
136136
logger: Logger,
137137
): Promise<string[]> {
138-
const jsonFilePath = actionsUtil.getDiffRangesJsonFilePath();
138+
const jsonFilePath = getDiffRangesJsonFilePath();
139139

140140
if (!fs.existsSync(jsonFilePath)) {
141141
logger.debug(

‎src/upload-lib.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { HTTPError } from "@actions/tool-cache";
66
import test from "ava";
77
import * as sinon from "sinon";
88

9-
import * as actionsUtil from "./actions-util";
109
import * as analyses from "./analyses";
1110
import { AnalysisKind, CodeQuality, CodeScanning } from "./analyses";
1211
import * as api from "./api-client";
@@ -1075,7 +1074,7 @@ function runFilterAlertsByDiffRange(
10751074
logger: Logger = new RecordingLogger(),
10761075
): Partial<sarif.Log> {
10771076
sinon.stub(diffUtils, "readDiffRangesJsonFile").returns(diffRanges);
1078-
sinon.stub(actionsUtil, "getDiffRangesJsonFilePath").returns("");
1077+
sinon.stub(diffUtils, "getDiffRangesJsonFilePath").returns("");
10791078
return uploadLib.filterAlertsByDiffRange(logger, input);
10801079
}
10811080

‎src/upload-lib.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import * as api from "./api-client";
1313
import { getGitHubVersion, wrapApiConfigurationError } from "./api-client";
1414
import { CodeQL, getCodeQL } from "./codeql";
1515
import type { ActionConfig } from "./config/action-config";
16-
import { readDiffRangesJsonFile } from "./diff-informed";
16+
import {
17+
getDiffRangesJsonFilePath,
18+
readDiffRangesJsonFile,
19+
} from "./diff-informed";
1720
import { ActionsEnvVars, EnvVar, exportEnvVar } from "./environment";
1821
import { FeatureEnablement } from "./feature-flags";
1922
import * as fingerprints from "./fingerprints";
@@ -1081,7 +1084,7 @@ export function filterAlertsByDiffRange(
10811084
): Partial<sarif.Log> {
10821085
const diffRanges = readDiffRangesJsonFile(
10831086
logger,
1084-
actionsUtil.getDiffRangesJsonFilePath(),
1087+
getDiffRangesJsonFilePath(),
10851088
);
10861089
if (!diffRanges?.length) {
10871090
return sarifLog;

0 commit comments

Comments
 (0)