Skip to content

Commit

Permalink
fix: Prevent boolean values for empty env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Feb 1, 2024
1 parent 2469ef8 commit 47b6fc0
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ function resolveSlug(envVars) {
return 'slug' in envVars ? envVars.slug : '';
}

/**
* @param {import('env-ci').CiEnv} data
* @param {string} key
* @returns {string | undefined}
*/
function getEnvCIVar(data, key) {
if (!data[key]) {
return undefined;
}

return data[key];
}

/**
* Extract CI environment variables using env-ci and custom fallback env vars
* @returns {EnvVars}
Expand Down Expand Up @@ -131,12 +144,12 @@ export function getEnvVars() {
key: customEnvVars.key,
endpoint: customEnvVars.endpoint,
isCi: envCIvars.isCi, // process.env.CI
service: customEnvVars.service || ('service' in envCIvars && envCIvars.service),
service: customEnvVars.service || getEnvCIVar(envCIvars, 'service'),
slug: customEnvVars.slug || resolveSlug(envCIvars),
branch: customEnvVars.branch || ('prBranch' in envCIvars && envCIvars.prBranch) || ('branch' in envCIvars && envCIvars.branch),
pr: customEnvVars.pr || ('pr' in envCIvars && envCIvars.pr),
build: customEnvVars.build || ('build' in envCIvars && envCIvars.build),
buildUrl: customEnvVars.buildUrl || ('buildUrl' in envCIvars && envCIvars.buildUrl),
branch: customEnvVars.branch || getEnvCIVar(envCIvars, 'prBranch') || getEnvCIVar(envCIvars, 'branch'),
pr: customEnvVars.pr || getEnvCIVar(envCIvars, 'pr'),
build: customEnvVars.build || getEnvCIVar(envCIvars, 'build'),
buildUrl: customEnvVars.buildUrl || getEnvCIVar(envCIvars, 'buildUrl'),
commit: customEnvVars.commit || envCIvars.commit,
commitMessage: customEnvVars.commitMessage,
};
Expand Down

0 comments on commit 47b6fc0

Please sign in to comment.