Skip to content
Snippets Groups Projects
Select Git revision
  • seb/ct-local
  • master default protected
  • randutil-remove-errors
  • herman/log-acme-errors-internally
  • herman/fix-non-constant-webhook-error-message
  • root-not-found-error-message
  • relative-paths-config
  • herman/wire-dpop-struct
  • herman/wrapped-listener
  • herman/configure-server-http-timeout
  • josh/fips
  • herman/acme-macos-properties
  • josh/webhook-error-response-content
  • user-regex
  • max/nebula-sign-curve
  • carl/bootstrap-error-clarity
  • max/capabilities
  • herman/acme-cname-txt
  • max/test
  • herman/acme-da-roots
  • backports
  • v0.28.4
  • v0.28.4-rc2
  • v0.28.4-rc1
  • v0.28.3-rc2
  • v0.28.3
  • v0.28.3-rc1
  • v0.28.2
  • v0.28.1
  • v0.28.1-rc2
  • v0.28.1-rc1
  • v0.28.0
  • v0.27.5
  • v0.27.4
  • v0.27.4-rc1
  • v0.27.3
  • v0.27.2
  • v0.27.1
  • v0.27.0
  • v0.26.2
  • v0.26.1
41 results

provisioner.go

Blame
  • commit.ts 1.73 KiB
    import is from '@sindresorhus/is';
    import minimatch from 'minimatch';
    import { CONFIG_SECRETS_EXPOSED } from '../../constants/error-messages';
    import { logger } from '../../logger';
    import { commitFiles } from '../../util/git';
    import { sanitize } from '../../util/sanitize';
    import { BranchConfig } from '../common';
    
    export function commitFilesToBranch(
      config: BranchConfig
    ): Promise<string | null> {
      let updatedFiles = config.updatedPackageFiles.concat(config.updatedArtifacts);
      // istanbul ignore if
      if (is.nonEmptyArray(config.excludeCommitPaths)) {
        updatedFiles = updatedFiles.filter((f) => {
          const filename = f.name === '|delete|' ? f.contents.toString() : f.name;
          const matchesExcludePaths = config.excludeCommitPaths.some((path) =>
            minimatch(filename, path, { dot: true })
          );
          if (matchesExcludePaths) {
            logger.debug(`Excluding ${filename} from commit`);
            return false;
          }
          return true;
        });
      }
      if (!is.nonEmptyArray(updatedFiles)) {
        logger.debug(`No files to commit`);
        return null;
      }
      const fileLength = [...new Set(updatedFiles.map((file) => file.name))].length;
      logger.debug(`${fileLength} file(s) to commit`);
      // istanbul ignore if
      if (config.dryRun) {
        logger.info('DRY-RUN: Would commit files to branch ' + config.branchName);
        return null;
      }
      // istanbul ignore if
      if (
        config.branchName !== sanitize(config.branchName) ||
        config.commitMessage !== sanitize(config.commitMessage)
      ) {
        throw new Error(CONFIG_SECRETS_EXPOSED);
      }
      // API will know whether to create new branch or not
      return commitFiles({
        branchName: config.branchName,
        files: updatedFiles,
        message: config.commitMessage,
        force: !!config.forceCommit,
      });
    }