Skip to content

Commit e0b8480

Browse files
henrymercerCopilot
andcommitted
Parse the config input in init without the parseConfigInput wrapper
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6cb83fa commit e0b8480

4 files changed

Lines changed: 17 additions & 75 deletions

File tree

‎lib/entry-points.js‎

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

‎src/config-utils.test.ts‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,40 +2347,6 @@ test("applyIncrementalAnalysisSettings: adds exclusions for diff-informed-only r
23472347
]);
23482348
});
23492349

2350-
test("parseConfigInput - returns undefined when the input isn't set", async (t) => {
2351-
await callee(configUtils.parseConfigInput)
2352-
.withArgs(undefined)
2353-
.passes(t.is, undefined);
2354-
});
2355-
2356-
test("parseConfigInput - parses the input as YAML", async (t) => {
2357-
await callee(configUtils.parseConfigInput)
2358-
.withArgs(simpleConfigFileContents)
2359-
.passes(t.deepEqual, {
2360-
name: "my config",
2361-
queries: [{ uses: "./foo_file" }],
2362-
});
2363-
});
2364-
2365-
test("parseConfigInput - throws a ConfigurationError naming the input if it isn't valid YAML", async (t) => {
2366-
await callee(configUtils.parseConfigInput)
2367-
.withArgs("queries: [")
2368-
.throws(t, {
2369-
instanceOf: ConfigurationError,
2370-
message: /^Cannot parse "`config` input"/,
2371-
});
2372-
});
2373-
2374-
test("parseConfigInput - throws a ConfigurationError naming the input if validation fails", async (t) => {
2375-
await callee(configUtils.parseConfigInput)
2376-
.withFeatures([Feature.ValidateDbConfig])
2377-
.withArgs("queries: 1")
2378-
.throws(t, {
2379-
instanceOf: ConfigurationError,
2380-
message: /^The configuration file "`config` input" is invalid/,
2381-
});
2382-
});
2383-
23842350
test("determineUserConfig - empty config when neither input is specified", async (t) => {
23852351
await withTmpDir(async (tmpDir) => {
23862352
const target = callee(configUtils.determineUserConfig)

‎src/config-utils.ts‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,29 +1044,6 @@ export async function applyIncrementalAnalysisSettings(
10441044
}
10451045
}
10461046

1047-
/**
1048-
* Parses the `config` input, which contains a configuration in YAML.
1049-
*
1050-
* @returns The configuration, or `undefined` if the input isn't set. Unless configuration validation
1051-
* is enabled, the configuration might not be a mapping.
1052-
* @throws A `ConfigurationError` if the input isn't valid YAML or, when configuration validation is
1053-
* enabled, isn't a valid configuration.
1054-
*/
1055-
export async function parseConfigInput(
1056-
{ logger, features }: ActionState<["Logger", "FeatureFlags"]>,
1057-
configInput: string | undefined,
1058-
): Promise<UserConfig | undefined> {
1059-
if (configInput === undefined) {
1060-
return undefined;
1061-
}
1062-
return parseUserConfig(
1063-
logger,
1064-
"`config` input",
1065-
configInput,
1066-
await features.getValue(Feature.ValidateDbConfig),
1067-
);
1068-
}
1069-
10701047
/**
10711048
* Determines where to load the `UserConfig` for the CLI from and loads it.
10721049
*

‎src/init-action.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
shouldRestoreCache,
2424
} from "./caching-utils";
2525
import { CodeQL } from "./codeql";
26+
import { parseUserConfig } from "./config/db-config";
2627
import { getConfigFileInput } from "./config/file";
2728
import { ComputedInput, getToolsInput } from "./config/inputs";
2829
import * as configUtils from "./config-utils";
@@ -306,10 +307,16 @@ async function run(
306307
const rawLanguages = configUtils.getRawLanguagesNoAutodetect(
307308
getOptionalInput("languages"),
308309
);
309-
const configInput = await configUtils.parseConfigInput(
310-
actionStateWithFeatures,
311-
getOptionalInput("config"),
312-
);
310+
const rawConfigInput = getOptionalInput("config");
311+
const configInput =
312+
rawConfigInput === undefined
313+
? undefined
314+
: parseUserConfig(
315+
logger,
316+
"`config` input",
317+
rawConfigInput,
318+
await features.getValue(Feature.ValidateDbConfig),
319+
);
313320
const queriesInput = getOptionalInput("queries");
314321
const otherLanguagePacksReason = getOtherLanguagePacksReason({
315322
configFile,

0 commit comments

Comments
 (0)