Apply suggestions from code review
This commit is contained in:
parent
7e086b240c
commit
bf97a6da5b
7 changed files with 55 additions and 24 deletions
18
lib/config-utils.js
generated
18
lib/config-utils.js
generated
|
|
@ -919,10 +919,12 @@ async function initConfig(languagesInput, queriesInput, packsInput, registriesIn
|
|||
exports.initConfig = initConfig;
|
||||
function parseRegistries(registriesInput) {
|
||||
try {
|
||||
return registriesInput ? yaml.l(registriesInput) : undefined;
|
||||
return registriesInput
|
||||
? yaml.load(registriesInput)
|
||||
: undefined;
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Invalid registries input. Must be a JSON string, but got: ${e instanceof Error ? e.message : String(e)}`);
|
||||
throw new Error("Invalid registries input. Must be a YAML string.");
|
||||
}
|
||||
}
|
||||
function isLocal(configPath) {
|
||||
|
|
@ -1054,6 +1056,18 @@ function createRegistriesBlock(registries) {
|
|||
};
|
||||
return qlconfig;
|
||||
}
|
||||
/**
|
||||
* Create a temporary environment based on the existing environment and overridden
|
||||
* by the given environment variables that are passed in as arguments.
|
||||
*
|
||||
* Use this new environment in the context of the given operation. After completing
|
||||
* the operation, restore the original environment.
|
||||
*
|
||||
* This function does not support un-setting environment variables.
|
||||
*
|
||||
* @param env
|
||||
* @param operation
|
||||
*/
|
||||
async function wrapEnvironment(env, operation) {
|
||||
// Remember the original env
|
||||
const oldEnv = { ...process.env };
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
8
lib/config-utils.test.js
generated
8
lib/config-utils.test.js
generated
|
|
@ -1105,7 +1105,9 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
|||
java: ["a", "b"],
|
||||
go: ["c", "d"],
|
||||
python: ["e", "f"],
|
||||
}, undefined, sampleApiDetails, tmpDir, logger);
|
||||
}, undefined, // registries
|
||||
sampleApiDetails, tmpDir, logger);
|
||||
// Expecting packs to be downloaded once for java and once for python
|
||||
t.deepEqual(packDownloadStub.callCount, 2);
|
||||
// no config file was created, so pass `undefined` as the config file path
|
||||
t.deepEqual(packDownloadStub.firstCall.args, [["a", "b"], undefined]);
|
||||
|
|
@ -1128,7 +1130,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
|||
{
|
||||
url: "https://containers.GHEHOSTNAME1/v2/",
|
||||
packages: "semmle/*",
|
||||
token: "still-a-token",
|
||||
token: "still-not-a-token",
|
||||
},
|
||||
];
|
||||
const expectedConfigFile = path.join(tmpDir, "qlconfig.yml");
|
||||
|
|
@ -1136,7 +1138,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
|||
packDownloadStub.callsFake((packs, configFile) => {
|
||||
t.deepEqual(configFile, expectedConfigFile);
|
||||
// verify the env vars were set correctly
|
||||
t.deepEqual(process.env.GITHUB_TOKEN, "token");
|
||||
t.deepEqual(process.env.GITHUB_TOKEN, sampleApiDetails.auth);
|
||||
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, "http://ghcr.io=not-a-token,https://containers.GHEHOSTNAME1/v2/=still-a-token");
|
||||
// verify the config file contents were set correctly
|
||||
const config = yaml.load(fs.readFileSync(configFile, "utf8"));
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue