Skip to content

Commit 4cd7a72

Browse files
committed
Remove loadConfig()
The loadConfig() function is mostly the same as getDefaultConfig(), except that it calls loadUserConfig() and stores the results in originalUserInput. This refactoring commit replaces the loadConfig() call with getDefaultConfig() and loadUserConfig(), which allows deleting a large amount of duplicated code.
1 parent f4358b3 commit 4cd7a72

File tree

1 file changed

+13
-102
lines changed

1 file changed

+13
-102
lines changed

src/config-utils.ts

Lines changed: 13 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,8 @@ export interface InitConfigInputs {
459459
logger: Logger;
460460
}
461461

462-
type GetDefaultConfigInputs = Omit<
463-
InitConfigInputs,
464-
"configFile" | "configInput"
465-
>;
466-
467-
type LoadConfigInputs = Omit<InitConfigInputs, "configInput"> & {
468-
configFile: string;
469-
};
470-
471462
/**
472-
* Get the default config for when the user has not supplied one.
463+
* Get the default config, populated without user configuration file.
473464
*/
474465
export async function getDefaultConfig({
475466
languagesInput,
@@ -490,7 +481,7 @@ export async function getDefaultConfig({
490481
githubVersion,
491482
features,
492483
logger,
493-
}: GetDefaultConfigInputs): Promise<Config> {
484+
}: InitConfigInputs): Promise<Config> {
494485
const languages = await getLanguages(
495486
codeql,
496487
languagesInput,
@@ -562,91 +553,6 @@ async function downloadCacheWithTime(
562553
return { trapCaches, trapCacheDownloadTime };
563554
}
564555

565-
/**
566-
* Load the config from the given file.
567-
*/
568-
async function loadConfig({
569-
languagesInput,
570-
queriesInput,
571-
qualityQueriesInput,
572-
packsInput,
573-
buildModeInput,
574-
configFile,
575-
dbLocation,
576-
trapCachingEnabled,
577-
dependencyCachingEnabled,
578-
debugMode,
579-
debugArtifactName,
580-
debugDatabaseName,
581-
repository,
582-
tempDir,
583-
codeql,
584-
workspacePath,
585-
sourceRoot,
586-
githubVersion,
587-
apiDetails,
588-
features,
589-
logger,
590-
}: LoadConfigInputs): Promise<Config> {
591-
const parsedYAML = await loadUserConfig(
592-
configFile,
593-
workspacePath,
594-
apiDetails,
595-
tempDir,
596-
);
597-
598-
const languages = await getLanguages(
599-
codeql,
600-
languagesInput,
601-
repository,
602-
logger,
603-
);
604-
605-
const buildMode = await parseBuildModeInput(
606-
buildModeInput,
607-
languages,
608-
features,
609-
logger,
610-
);
611-
612-
const augmentationProperties = await calculateAugmentation(
613-
codeql,
614-
repository,
615-
features,
616-
packsInput,
617-
queriesInput,
618-
qualityQueriesInput,
619-
languages,
620-
sourceRoot,
621-
buildMode,
622-
logger,
623-
);
624-
625-
const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime(
626-
trapCachingEnabled,
627-
codeql,
628-
languages,
629-
logger,
630-
);
631-
632-
return {
633-
languages,
634-
buildMode,
635-
originalUserInput: parsedYAML,
636-
tempDir,
637-
codeQLCmd: codeql.getPath(),
638-
gitHubVersion: githubVersion,
639-
dbLocation: dbLocationOrDefault(dbLocation, tempDir),
640-
debugMode,
641-
debugArtifactName,
642-
debugDatabaseName,
643-
augmentationProperties,
644-
trapCaches,
645-
trapCacheDownloadTime,
646-
dependencyCachingEnabled: getCachingKind(dependencyCachingEnabled),
647-
};
648-
}
649-
650556
async function loadUserConfig(
651557
configFile: string,
652558
workspacePath: string,
@@ -1065,8 +971,6 @@ function userConfigFromActionPath(tempDir: string): string {
1065971
* a default config. The parsed config is then stored to a known location.
1066972
*/
1067973
export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
1068-
let config: Config;
1069-
1070974
const { logger, tempDir } = inputs;
1071975

1072976
// if configInput is set, it takes precedence over configFile
@@ -1081,15 +985,22 @@ export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
1081985
logger.debug(`Using config from action input: ${inputs.configFile}`);
1082986
}
1083987

1084-
// If no config file was provided create an empty one
988+
let userConfig: UserConfig = {};
1085989
if (!inputs.configFile) {
1086990
logger.debug("No configuration file was provided");
1087-
config = await getDefaultConfig(inputs);
1088991
} else {
1089-
// Convince the type checker that inputs.configFile is defined.
1090-
config = await loadConfig({ ...inputs, configFile: inputs.configFile });
992+
logger.debug(`Using configuration file: ${inputs.configFile}`);
993+
userConfig = await loadUserConfig(
994+
inputs.configFile,
995+
inputs.workspacePath,
996+
inputs.apiDetails,
997+
tempDir,
998+
);
1091999
}
10921000

1001+
const config = await getDefaultConfig(inputs);
1002+
config.originalUserInput = userConfig;
1003+
10931004
// Save the config so we can easily access it again in the future
10941005
await saveConfig(config, logger);
10951006
return config;

0 commit comments

Comments
 (0)