Skip to content
Snippets Groups Projects
Select Git revision
  • c13c49863e3e2381dd6e05b671f062d2ea3d5ef7
  • master default
2 results

gh-got-wrapper.js

Blame
  • generate.ts 12.25 KiB
    import is from '@sindresorhus/is';
    import { DateTime } from 'luxon';
    import mdTable from 'markdown-table';
    import semver from 'semver';
    import { mergeChildConfig } from '../../../config';
    import { CONFIG_SECRETS_EXPOSED } from '../../../constants/error-messages';
    import { logger } from '../../../logger';
    import { newlineRegex, regEx } from '../../../util/regex';
    import { sanitize } from '../../../util/sanitize';
    import * as template from '../../../util/template';
    import type { BranchConfig, BranchUpgradeConfig } from '../../types';
    import { CommitMessage } from '../model/commit-message';
    
    function isTypesGroup(branchUpgrades: BranchUpgradeConfig[]): boolean {
      return (
        branchUpgrades.some(({ depName }) => depName?.startsWith('@types/')) &&
        new Set(
          branchUpgrades.map(({ depName }) => depName?.replace(/^@types\//, ''))
        ).size === 1
      );
    }
    
    function sortTypesGroup(upgrades: BranchUpgradeConfig[]): void {
      const isTypesUpgrade = ({ depName }: BranchUpgradeConfig): boolean =>
        depName?.startsWith('@types/');
      const regularUpgrades = upgrades.filter(
        (upgrade) => !isTypesUpgrade(upgrade)
      );
      const typesUpgrades = upgrades.filter(isTypesUpgrade);
      upgrades.splice(0, upgrades.length);
      upgrades.push(...regularUpgrades, ...typesUpgrades);
    }
    
    function getTableValues(
      upgrade: BranchUpgradeConfig
    ): [string, string, string, string] | null {
      if (!upgrade.commitBodyTable) {
        return null;
      }
      const { datasource, packageName, depName, currentVersion, newVersion } =
        upgrade;
      const name = packageName || depName;
      if (datasource && name && currentVersion && newVersion) {
        return [datasource, name, currentVersion, newVersion];
      }
      logger.debug(
        {
          datasource,
          packageName,
          depName,
          currentVersion,
          newVersion,
        },
        'Cannot determine table values'
      );
      return null;
    }
    
    export function generateBranchConfig(
      upgrades: BranchUpgradeConfig[]
    ): BranchConfig {
      let branchUpgrades = upgrades;
      if (!branchUpgrades.every((upgrade) => upgrade.pendingChecks)) {
        // If the branch isn't pending, then remove any upgrades within which *are*
        branchUpgrades = branchUpgrades.filter((upgrade) => !upgrade.pendingChecks);
      }
      logger.trace({ config: branchUpgrades }, 'generateBranchConfig');
      let config: BranchConfig = {
        upgrades: [],
      } as any;