Skip to content
Snippets Groups Projects
Select Git revision
  • 1fe7ab7b68b07b35e752d7273aff2aaa3145f39c
  • main default protected
  • renovate/main-renovatebot-github-action-43.x
  • next
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • chore/punycode
  • 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
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.45.0
  • 41.44.0
  • 41.43.7
  • 41.43.6
  • 41.43.5
  • 41.43.4
  • 41.43.3
  • 41.43.2
  • 41.43.1
  • 41.43.0
  • 41.42.12
  • 41.42.11
  • 41.42.10
  • 41.42.9
  • 41.42.8
  • 41.42.7
  • 41.42.6
  • 41.42.5
  • 41.42.4
  • 41.42.3
41 results

array.spec.ts

Blame
  • errors-warnings.ts 4.39 KiB
    // TODO #22198
    import type { RenovateConfig } from '../../config/types';
    import { logger } from '../../logger';
    import type { PackageFile } from '../../modules/manager/types';
    import { coerceArray } from '../../util/array';
    import { emojify } from '../../util/emoji';
    import { regEx } from '../../util/regex';
    import type { DepWarnings } from '../types';
    
    export function getWarnings(config: RenovateConfig): string {
      if (!config.warnings?.length) {
        return '';
      }
      let warningText = `\n# Warnings (${config.warnings.length})\n\n`;
      warningText += `Please correct - or verify that you can safely ignore - these warnings before you merge this PR.\n\n`;
      for (const w of config.warnings) {
        warningText += `-   \`${w.topic}\`: ${w.message}\n`;
      }
      warningText += '\n---\n';
      return warningText;
    }
    
    export function getErrors(config: RenovateConfig): string {
      if (!config.errors?.length) {
        return '';
      }
      let errorText = `\n# Errors (${config.errors.length})\n\n`;
      errorText += `Renovate has found errors that you should fix (in this branch) before finishing this PR.\n\n`;
      for (const e of config.errors) {
        errorText += `-   \`${e.topic}\`: ${e.message}\n`;
      }
      errorText += '\n---\n';
      return errorText;
    }
    
    function getDepWarnings(
      packageFiles: Record<string, PackageFile[]>
    ): DepWarnings {
      const warnings: string[] = [];
      const warningFiles: string[] = [];
      for (const files of Object.values(packageFiles ?? {})) {
        for (const file of files ?? []) {
          // TODO: remove condition when type is fixed (#22198)
          if (file.packageFile) {
            for (const dep of coerceArray(file.deps)) {
              for (const w of coerceArray(dep.warnings)) {
                const message = w.message;
                if (!warnings.includes(message)) {
                  warnings.push(message);
                }
                if (!warningFiles.includes(file.packageFile)) {
                  warningFiles.push(file.packageFile);
                }
              }
            }
          }
        }
      }
      if (warnings.length) {
        logger.warn({ warnings, files: warningFiles }, 'Package lookup failures');
      }
      return { warnings, warningFiles };
    }
    
    export function getDepWarningsOnboardingPR(
      packageFiles: Record<string, PackageFile[]>,
      config: RenovateConfig
    ): string {
      const { warnings, warningFiles } = getDepWarnings(packageFiles);
      if (config.suppressNotifications?.includes('dependencyLookupWarnings')) {
        return '';
      }
      let warningText = '';
      if (!warnings.length) {
        return '';
      }
      warningText = emojify(`\n---\n> \n> :warning: **Warning**\n> \n`);
      warningText += `> Please correct - or verify that you can safely ignore - these dependency lookup failures before you merge this PR.\n> \n`;
      for (const w of warnings) {
        warningText += `> -   \`${w}\`\n`;
      }
      warningText +=
        '> \n> Files affected: ' +
        warningFiles.map((f) => '`' + f + '`').join(', ') +
        '\n\n';
      return warningText;
    }
    
    export function getDepWarningsPR(
      packageFiles: Record<string, PackageFile[]>,
      config: RenovateConfig,
      dependencyDashboard?: boolean
    ): string {
      const { warnings } = getDepWarnings(packageFiles);
      if (config.suppressNotifications?.includes('dependencyLookupWarnings')) {
        return '';
      }
      let warningText = '';
      if (!warnings.length) {
        return '';
      }
      warningText = emojify(`\n---\n\n> :warning: **Warning**\n> \n`);
      warningText += '> Some dependencies could not be looked up. ';
      if (dependencyDashboard) {
        warningText += `Check the Dependency Dashboard for more information.\n\n`;
      } else {
        warningText += `Check the warning logs for more information.\n\n`;
      }
      return warningText;
    }
    
    export function getDepWarningsDashboard(
      packageFiles: Record<string, PackageFile[]>,
      config: RenovateConfig
    ): string {
      if (config.suppressNotifications?.includes('dependencyLookupWarnings')) {
        return '';
      }
      const { warnings, warningFiles } = getDepWarnings(packageFiles);
      if (!warnings.length) {
        return '';
      }
    
      const depWarnings = warnings
        .map((w) =>
          w.replace(regEx(/^Failed to look up(?: [-\w]+)? dependency /), '')
        )
        .map((dep) => '`' + dep + '`')
        .join(', ');
    
      let warningText = emojify(
        `\n---\n\n> :warning: **Warning**\n> \n> Renovate failed to look up the following dependencies: `
      );
      warningText += depWarnings;
      warningText += '.\n> \n> Files affected: ';
      warningText += warningFiles.map((f) => '`' + f + '`').join(', ');
      warningText += '\n\n---\n\n';
      return warningText;
    }