Skip to content

Commit 287a445

Browse files
committed
Extract resolve-tools-input to module
1 parent 96ff4e3 commit 287a445

File tree

6 files changed

+93
-88
lines changed

6 files changed

+93
-88
lines changed

lib/init-action.js

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

lib/setup-codeql-action.js

Lines changed: 20 additions & 19 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 & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,6 @@ export const getOptionalInput = function (name: string): string | undefined {
4646
return value.length > 0 ? value : undefined;
4747
};
4848

49-
/**
50-
* Resolves the effective tools input by combining workflow input and repository properties.
51-
* The explicit `tools` workflow input takes precedence. If none is provided,
52-
* fall back to the repository property (if set).
53-
*
54-
* @param repositoryProperties - The loaded repository properties object
55-
* @param toolsPropertyName - The name of the tools property to look up
56-
* @param logger - Logger for outputting resolution messages
57-
* @returns The effective tools input value
58-
*/
59-
export function resolveToolsInput(
60-
repositoryProperties: Record<string, any>,
61-
toolsPropertyName: string,
62-
logger: Logger,
63-
): string | undefined {
64-
const toolsWorkflowInput = getOptionalInput("tools");
65-
const toolsPropertyValue: string | undefined =
66-
repositoryProperties[toolsPropertyName];
67-
const effectiveToolsInput = toolsWorkflowInput ?? toolsPropertyValue;
68-
69-
// Log the source of the tools input for transparency
70-
if (effectiveToolsInput) {
71-
if (toolsWorkflowInput) {
72-
logger.info(
73-
`Setting tools: ${effectiveToolsInput} based on workflow input.`,
74-
);
75-
} else {
76-
logger.info(
77-
`Setting tools: ${effectiveToolsInput} based on the '${toolsPropertyName}' repository property.`,
78-
);
79-
}
80-
}
81-
82-
return effectiveToolsInput;
83-
}
84-
8549
export function getTemporaryDirectory(): string {
8650
const value = process.env["CODEQL_ACTION_TEMP"];
8751
return value !== undefined && value !== ""

src/init-action.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getRequiredInput,
1515
getTemporaryDirectory,
1616
persistInputs,
17-
resolveToolsInput,
1817
} from "./actions-util";
1918
import { AnalysisKind, getAnalysisKinds } from "./analyses";
2019
import { getGitHubVersion, GitHubApiCombinedDetails } from "./api-client";
@@ -66,6 +65,7 @@ import {
6665
} from "./overlay/caching";
6766
import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
6867
import { getRepositoryNwo } from "./repository";
68+
import { resolveToolsInput } from "./resolve-tools-input";
6969
import { ToolsSource } from "./setup-codeql";
7070
import {
7171
ActionName,
@@ -307,7 +307,6 @@ async function run(startedAt: Date) {
307307
// fall back to the 'github-codeql-tools' repository property (if set).
308308
effectiveToolsInput = resolveToolsInput(
309309
repositoryPropertiesResult.orElse({}),
310-
RepositoryPropertyName.TOOLS,
311310
logger,
312311
);
313312

src/resolve-tools-input.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getOptionalInput } from "./actions-util";
2+
import {
3+
RepositoryProperties,
4+
RepositoryPropertyName,
5+
} from "./feature-flags/properties";
6+
import { Logger } from "./logging";
7+
8+
/**
9+
* Resolves the effective tools input by combining workflow input and repository properties.
10+
* The explicit `tools` workflow input takes precedence. If none is provided,
11+
* fall back to the repository property (if set).
12+
*
13+
* @param repositoryProperties - The loaded repository properties object
14+
* @param logger - Logger for outputting resolution messages
15+
* @returns The effective tools input value
16+
*/
17+
export function resolveToolsInput(
18+
repositoryProperties: RepositoryProperties,
19+
logger: Logger,
20+
): string | undefined {
21+
const toolsWorkflowInput = getOptionalInput("tools");
22+
const toolsPropertyValue: string | undefined =
23+
RepositoryPropertyName.TOOLS in repositoryProperties
24+
? repositoryProperties[RepositoryPropertyName.TOOLS]
25+
: undefined;
26+
const effectiveToolsInput = toolsWorkflowInput ?? toolsPropertyValue;
27+
28+
// Log the source of the tools input for transparency
29+
if (effectiveToolsInput) {
30+
if (toolsWorkflowInput) {
31+
logger.info(
32+
`Setting tools: ${effectiveToolsInput} based on workflow input.`,
33+
);
34+
} else {
35+
logger.info(
36+
`Setting tools: ${effectiveToolsInput} based on the '${RepositoryPropertyName.TOOLS}' repository property.`,
37+
);
38+
}
39+
}
40+
41+
return effectiveToolsInput;
42+
}

src/setup-codeql-action.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ import {
66
getOptionalInput,
77
getRequiredInput,
88
getTemporaryDirectory,
9-
resolveToolsInput,
109
} from "./actions-util";
1110
import { getGitHubVersion } from "./api-client";
1211
import { CodeQL } from "./codeql";
1312
import { EnvVar } from "./environment";
1413
import { initFeatures } from "./feature-flags";
15-
import {
16-
loadRepositoryProperties,
17-
RepositoryPropertyName,
18-
} from "./feature-flags/properties";
14+
import { loadRepositoryProperties } from "./feature-flags/properties";
1915
import { initCodeQL } from "./init";
2016
import { getActionsLogger, Logger } from "./logging";
2117
import { getRepositoryNwo } from "./repository";
18+
import { resolveToolsInput } from "./resolve-tools-input";
2219
import { ToolsSource } from "./setup-codeql";
2320
import {
2421
ActionName,
@@ -157,8 +154,9 @@ async function run(startedAt: Date): Promise<void> {
157154
// The explicit `tools` workflow input takes precedence. If none is provided,
158155
// fall back to the 'github-codeql-tools' repository property (if set).
159156
effectiveToolsInput = resolveToolsInput(
160-
repositoryPropertiesResult,
161-
RepositoryPropertyName.TOOLS,
157+
repositoryPropertiesResult.isSuccess()
158+
? repositoryPropertiesResult.value
159+
: {},
162160
logger,
163161
);
164162

0 commit comments

Comments
 (0)