Skip to content
Snippets Groups Projects
Select Git revision
  • dca3418bbdbf1024ac6807e591562b4042bc846d
  • main default protected
  • renovate/main-renovatebot-osv-offline-1.x
  • fix/36927-maven-tags
  • renovate/main-redis-5.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • fix/36615b-branch-reuse-no-cache
  • 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
  • 41.37.7
  • 41.37.6
  • 41.37.5
  • 41.37.4
  • 41.37.3
  • 41.37.2
  • 41.37.1
  • 41.37.0
  • 41.36.2
  • 41.36.1
  • 41.36.0
  • 41.35.2
  • 41.35.1
  • 41.35.0
  • 41.34.1
  • 41.34.0
  • 41.33.0
  • 41.32.3
  • 41.32.2
  • 41.32.1
41 results

parse.ts

Blame
  • parse.ts 1.28 KiB
    import { regEx } from '../../../util/regex';
    import { isSingleVersion, parseRange, rangeToStr } from '../maven/compare';
    
    const REV_TYPE_LATEST = 'REV_TYPE_LATEST';
    const REV_TYPE_SUBREV = 'REV_TYPE_SUBREVISION';
    const REV_TYPE_RANGE = 'REV_TYPE_RANGE';
    
    export interface Revision {
      type: typeof REV_TYPE_LATEST | typeof REV_TYPE_RANGE | typeof REV_TYPE_SUBREV;
    
      value: string;
    }
    
    export const LATEST_REGEX = regEx(/^latest\.|^latest$/i);
    
    function parseDynamicRevision(str: string): Revision | null {
      if (!str) {
        return null;
      }
    
      if (LATEST_REGEX.test(str)) {
        const value = str.replace(LATEST_REGEX, '').toLowerCase() || '';
        return {
          type: REV_TYPE_LATEST,
          value: value === 'integration' ? '' : value,
        };
      }
    
      const SUBREV_REGEX = regEx(/\.\+$/);
      if (str.endsWith('.+')) {
        const value = str.replace(SUBREV_REGEX, '');
        if (isSingleVersion(value)) {
          return {
            type: REV_TYPE_SUBREV,
            value,
          };
        }
      }
    
      const range = parseRange(str);
      if (range && range.length === 1) {
        const rangeValue = rangeToStr(range);
        if (rangeValue) {
          return {
            type: REV_TYPE_RANGE,
            value: rangeValue,
          };
        }
      }
    
      return null;
    }
    
    export {
      REV_TYPE_LATEST,
      REV_TYPE_SUBREV,
      REV_TYPE_RANGE,
      parseDynamicRevision,
    };