Skip to content
Snippets Groups Projects
Select Git revision
  • 8acfc0d801a1671b4a86cae6bb7cd0d3a8b97f30
  • main default protected
  • renovate/main-ghcr.io-renovatebot-base-image-10.x
  • renovate/main-ghcr.io-containerbase-devcontainer-13.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
  • 41.27.1
  • 41.27.0
  • 41.26.2
  • 41.26.1
  • 41.26.0
  • 41.25.1
  • 41.25.0
41 results

dependency-dashboard.spec.ts

Blame
  • index.ts 3.68 KiB
    import { RenovateConfig, mergeChildConfig } from '../../../config';
    import { logger } from '../../../logger';
    import { PackageFile } from '../../../manager/common';
    import { platform } from '../../../platform';
    import { branchExists } from '../../../util/git';
    import { addSplit } from '../../../util/split';
    import { BranchConfig } from '../../common';
    import { ExtractResult, extract, lookup, update } from './extract-update';
    import { WriteUpdateResult } from './write';
    
    function getBaseBranchConfig(
      baseBranch: string,
      config: RenovateConfig
    ): RenovateConfig {
      logger.debug(`baseBranch: ${baseBranch}`);
      const baseBranchConfig = mergeChildConfig(config, { baseBranch });
      if (config.baseBranches.length > 1) {
        baseBranchConfig.branchPrefix += `${baseBranch}-`;
        baseBranchConfig.hasBaseBranches = true;
      }
      return baseBranchConfig;
    }
    
    export async function extractDependencies(
      config: RenovateConfig
    ): Promise<ExtractResult> {
      logger.debug('processRepo()');
      /* eslint-disable no-param-reassign */
      config.dependencyDashboardChecks = {};
      const stringifiedConfig = JSON.stringify(config);
      // istanbul ignore next
      if (
        config.dependencyDashboard ||
        stringifiedConfig.includes('"dependencyDashboardApproval":true') ||
        stringifiedConfig.includes('"prCreation":"approval"')
      ) {
        config.dependencyDashboardTitle =
          config.dependencyDashboardTitle || `Dependency Dashboard`;
        const issue = await platform.findIssue(config.dependencyDashboardTitle);
        if (issue) {
          const checkMatch = ' - \\[x\\] <!-- ([a-zA-Z]+)-branch=([^\\s]+) -->';
          const checked = issue.body.match(new RegExp(checkMatch, 'g'));
          if (checked?.length) {
            const re = new RegExp(checkMatch);
            checked.forEach((check) => {
              const [, type, branchName] = re.exec(check);
              config.dependencyDashboardChecks[branchName] = type;
            });
          }
          const checkedRebaseAll = issue.body.includes(
            ' - [x] <!-- rebase-all-open-prs -->'
          );
          if (checkedRebaseAll) {
            config.dependencyDashboardRebaseAllOpen = true;
            /* eslint-enable no-param-reassign */
          }
        }
      }
      let res: ExtractResult = {
        branches: [],
        branchList: [],
        packageFiles: null,
      };
      if (config.baseBranches?.length) {
        logger.debug({ baseBranches: config.baseBranches }, 'baseBranches');
        const extracted: Record<string, Record<string, PackageFile[]>> = {};
        for (const baseBranch of config.baseBranches) {
          if (branchExists(baseBranch)) {
            const baseBranchConfig = getBaseBranchConfig(baseBranch, config);
            extracted[baseBranch] = await extract(baseBranchConfig);
          } else {
            logger.warn({ baseBranch }, 'Base branch does not exist - skipping');
          }
        }
        addSplit('extract');
        for (const baseBranch of config.baseBranches) {
          if (branchExists(baseBranch)) {
            const baseBranchConfig = getBaseBranchConfig(baseBranch, config);
            const packageFiles = extracted[baseBranch];
            const baseBranchRes = await lookup(baseBranchConfig, packageFiles);
            res.branches = res.branches.concat(baseBranchRes?.branches);
            res.branchList = res.branchList.concat(baseBranchRes?.branchList);
            res.packageFiles = res.packageFiles || baseBranchRes?.packageFiles; // Use the first branch
          }
        }
      } else {
        logger.debug('No baseBranches');
        const packageFiles = await extract(config);
        addSplit('extract');
        res = await lookup(config, packageFiles);
      }
      addSplit('lookup');
      return res;
    }
    
    export function updateRepo(
      config: RenovateConfig,
      branches: BranchConfig[]
    ): Promise<WriteUpdateResult | undefined> {
      logger.debug('processRepo()');
    
      return update(config, branches);
    }