Skip to content
Snippets Groups Projects
Select Git revision
  • ea60c14d049123067ed1eae716d77effecab7ff5
  • main default protected
  • ansprechpersonen-aktualisiert-ws23_24
  • renovate/gitbeaker-rest-40.x
  • renovate/sveltejs-adapter-node-5.x
  • renovate/docker-dockerfile-1.x
  • renovate/prettier-3.x
  • renovate/sveltejs-kit-2.x
  • renovate/vitest-1.x
  • renovate/vite-5.x
  • renovate/node-21.x
  • renovate/eslint-config-prettier-9.x
  • renovate/prettier-plugin-svelte-3.x
  • migrate-to-oauth
14 results

check_envs.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    check_envs.js 1.85 KiB
    function isNonEmptyString(value) {
      return typeof value === "string" && value.length > 0;
    }
    
    /**
     * If targetEnv is empty/not set, set it to the first alias that has contains a value
     * @param {string} targetEnv the name of the env that aliases should map to
     * @param {string[]} aliases aliases for targetEnv
     * @returns targetEnv's value or the first non empty alias value
     */
    function aliasEnv(targetEnv, aliases) {
      targetEnv = targetEnv.toUpperCase();
      aliases = aliases.map((alias) => alias.toUpperCase());
      if (
        typeof process.env[targetEnv] === "string" &&
        process.env[targetEnv].length > 0
      ) {
        return process.env[targetEnv];
      } else {
        for (const alias of aliases) {
          const value = process.env[alias];
          if (typeof value === "string" && value.length > 0) {
            process.env[targetEnv] = value;
            return value;
          }
        }
      }
      // Nothing found, all empty
      return undefined;
    }
    
    /**
     * Check if all envs exist and print errors otherwise.
     * @param {{name: string, aliases: string[], description: string, whereToGetIt: string?}[]} envsWithDescriptions
     * @returns array of error messages
     */
    function checkAllEnvsExist(envsWithDescriptions) {
      let errorMessages = [];
    
      for (const {
        name,
        aliases,
        description,
        whereToGetIt,
      } of envsWithDescriptions) {
        const value = aliasEnv(name, aliases);
        if (!isNonEmptyString(value)) {
          const aliasMessage =
            aliases.length > 0 ? " (Aliases: " + aliases.join(", ") + ")" : "";
          const whereToGetItText = whereToGetIt
            ? "\n└ You can request it here: " + whereToGetIt
            : "";
          const errrorMessage = `
    Environment variable ${name}${aliasMessage} is not set.
    └ Description: ${description}${whereToGetItText}
    `;
          errorMessages.push(errrorMessage);
        }
      }
      return errorMessages;
    }
    
    module.exports.checkAllEnvsExist = checkAllEnvsExist;