Skip to content

Commit f4358b3

Browse files
committed
Extract loadUserConfig()
1 parent f53ec7c commit f4358b3

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/config-utils.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -588,23 +588,12 @@ async function loadConfig({
588588
features,
589589
logger,
590590
}: LoadConfigInputs): Promise<Config> {
591-
let parsedYAML: UserConfig;
592-
593-
if (isLocal(configFile)) {
594-
if (configFile !== userConfigFromActionPath(tempDir)) {
595-
// If the config file is not generated by the Action, it should be relative to the workspace.
596-
configFile = path.resolve(workspacePath, configFile);
597-
// Error if the config file is now outside of the workspace
598-
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {
599-
throw new ConfigurationError(
600-
getConfigFileOutsideWorkspaceErrorMessage(configFile),
601-
);
602-
}
603-
}
604-
parsedYAML = getLocalConfig(configFile);
605-
} else {
606-
parsedYAML = await getRemoteConfig(configFile, apiDetails);
607-
}
591+
const parsedYAML = await loadUserConfig(
592+
configFile,
593+
workspacePath,
594+
apiDetails,
595+
tempDir,
596+
);
608597

609598
const languages = await getLanguages(
610599
codeql,
@@ -658,6 +647,29 @@ async function loadConfig({
658647
};
659648
}
660649

650+
async function loadUserConfig(
651+
configFile: string,
652+
workspacePath: string,
653+
apiDetails: api.GitHubApiCombinedDetails,
654+
tempDir: string,
655+
): Promise<UserConfig> {
656+
if (isLocal(configFile)) {
657+
if (configFile !== userConfigFromActionPath(tempDir)) {
658+
// If the config file is not generated by the Action, it should be relative to the workspace.
659+
configFile = path.resolve(workspacePath, configFile);
660+
// Error if the config file is now outside of the workspace
661+
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {
662+
throw new ConfigurationError(
663+
getConfigFileOutsideWorkspaceErrorMessage(configFile),
664+
);
665+
}
666+
}
667+
return getLocalConfig(configFile);
668+
} else {
669+
return await getRemoteConfig(configFile, apiDetails);
670+
}
671+
}
672+
661673
/**
662674
* Calculates how the codeql config file needs to be augmented before passing
663675
* it to the CLI. The reason this is necessary is the codeql-action can be called

0 commit comments

Comments
 (0)