Add a new function used to determine where to retrieve config from
This commit is contained in:
parent
f4cf65ca2d
commit
153a598a97
6 changed files with 40 additions and 2 deletions
8
lib/config-utils.js
generated
8
lib/config-utils.js
generated
|
|
@ -219,6 +219,14 @@ function initConfig() {
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
function isLocal(configPath) {
|
||||||
|
// If the path starts with ./, look locally
|
||||||
|
if (configPath.indexOf("./") === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return (configPath.indexOf("@") === -1);
|
||||||
|
}
|
||||||
|
exports.isLocal = isLocal;
|
||||||
function getConfigFolder() {
|
function getConfigFolder() {
|
||||||
return util.getRequiredEnvParam('RUNNER_TEMP');
|
return util.getRequiredEnvParam('RUNNER_TEMP');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
9
lib/config-utils.test.js
generated
9
lib/config-utils.test.js
generated
|
|
@ -137,6 +137,15 @@ ava_1.default("Octokit not used when reading local config", async (t) => {
|
||||||
t.false(spyKit.called);
|
t.false(spyKit.called);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ava_1.default("Remote and local configuration paths correctly identified", t => {
|
||||||
|
// If the path starts with ./, look locally
|
||||||
|
t.assert(configUtils.isLocal('./file'));
|
||||||
|
t.assert(configUtils.isLocal('./file@name'));
|
||||||
|
// Otherwise, if the path contains @ (branch specifier), assume it's a remote repo
|
||||||
|
t.false(configUtils.isLocal('octo-org/codeql-config/config.yaml@main'));
|
||||||
|
// Otherwise look locally (this is the fallback)
|
||||||
|
t.assert(configUtils.isLocal('file'));
|
||||||
|
});
|
||||||
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
||||||
ava_1.default("load invalid input - " + testName, async (t) => {
|
ava_1.default("load invalid input - " + testName, async (t) => {
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -152,6 +152,18 @@ test("Octokit not used when reading local config", async t => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Remote and local configuration paths correctly identified", t => {
|
||||||
|
// If the path starts with ./, look locally
|
||||||
|
t.assert(configUtils.isLocal('./file'));
|
||||||
|
t.assert(configUtils.isLocal('./file@name'));
|
||||||
|
|
||||||
|
// Otherwise, if the path contains @ (branch specifier), assume it's a remote repo
|
||||||
|
t.false(configUtils.isLocal('octo-org/codeql-config/config.yaml@main'));
|
||||||
|
|
||||||
|
// Otherwise look locally (this is the fallback)
|
||||||
|
t.assert(configUtils.isLocal('file'));
|
||||||
|
});
|
||||||
|
|
||||||
function doInvalidInputTest(
|
function doInvalidInputTest(
|
||||||
testName: string,
|
testName: string,
|
||||||
inputFileContents: string,
|
inputFileContents: string,
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,15 @@ function initConfig(): Config {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isLocal(configPath: string): boolean {
|
||||||
|
// If the path starts with ./, look locally
|
||||||
|
if (configPath.indexOf("./") === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (configPath.indexOf("@") === -1);
|
||||||
|
}
|
||||||
|
|
||||||
function getConfigFolder(): string {
|
function getConfigFolder(): string {
|
||||||
return util.getRequiredEnvParam('RUNNER_TEMP');
|
return util.getRequiredEnvParam('RUNNER_TEMP');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue