Skip to content
Snippets Groups Projects
Select Git revision
  • 520429f1bd7e15f2fba7f838a3b08f51e7127e04
  • main default protected
  • next
  • 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
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.17.2
  • 41.17.1
  • 41.17.0
  • 41.16.3
  • 41.16.2
  • 41.16.1
  • 41.16.0
  • 41.15.0
  • 41.14.0
  • 41.13.1
  • 41.13.0
  • 41.12.1
  • 41.12.0
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
41 results

index.ts

Blame
  • index.ts NaN GiB
    import { DateTime } from 'luxon';
    import { regEx } from '../../../util/regex';
    import { DistroInfo } from '../distro';
    import type { NewValueConfig, VersioningApi } from '../types';
    
    export const id = 'ubuntu';
    export const displayName = 'Ubuntu';
    export const urls = [
      'https://changelogs.ubuntu.com/meta-release',
      'https://debian.pages.debian.net/distro-info-data/ubuntu.csv',
    ];
    export const supportsRanges = false;
    
    const di = new DistroInfo('data/ubuntu-distro-info.json');
    
    // validation
    
    function isValid(input: string): boolean {
      return (
        (typeof input === 'string' &&
          regEx(/^(0[4-5]|[6-9]|[1-9][0-9])\.[0-9][0-9](\.[0-9]{1,2})?$/).test(
            input
          )) ||
        di.isCodename(input)
      );
    }
    
    function isVersion(input: string): boolean {
      return isValid(input);
    }
    
    function isCompatible(version: string, _current?: string): boolean {
      return isValid(version);
    }
    
    function isSingleVersion(version: string): boolean {
      return isValid(version);
    }
    
    function isStable(version: string): boolean {
      const ver = di.getVersionByCodename(version);
      if (!isValid(ver)) {
        return false;
      }
    
      const schedule = di.getSchedule(ver);
      if (schedule && DateTime.fromISO(schedule.release) > DateTime.now()) {
        return false;
      }
    
      return regEx(/^\d?[02468]\.04/).test(ver);
    }
    
    // digestion of version
    
    function getMajor(version: string): null | number {
      const ver = di.getVersionByCodename(version);
      if (isValid(ver)) {
        const [major] = ver.split('.');
        return parseInt(major, 10);
      }
      return null;
    }
    
    function getMinor(version: string): null | number {
      const ver = di.getVersionByCodename(version);
      if (isValid(ver)) {
        const [, minor] = ver.split('.');
        return parseInt(minor, 10);
      }
      return null;
    }
    
    function getPatch(version: string): null | number {
      const ver = di.getVersionByCodename(version);
      if (isValid(ver)) {
        const [, , patch] = ver.split('.');
        return patch ? parseInt(patch, 10) : null;
      }
      return null;
    }
    
    // comparison
    
    function equals(version: string, other: string): boolean {
      const ver = di.getVersionByCodename(version);
      const otherVer = di.getVersionByCodename(other);
      return isVersion(ver) && isVersion(otherVer) && ver === otherVer;
    }
    
    function isGreaterThan(version: string, other: string): boolean {
      const xMajor = getMajor(version) ?? 0;
      const yMajor = getMajor(other) ?? 0;
      if (xMajor > yMajor) {
        return true;
      }
      if (xMajor < yMajor) {
        return false;
      }
    
      const xMinor = getMinor(version) ?? 0;
      const yMinor = getMinor(other) ?? 0;
      if (xMinor > yMinor) {
        return true;
      }
      if (xMinor < yMinor) {
        return false;
      }
    
      const xPatch = getPatch(version) ?? 0;
      const yPatch = getPatch(other) ?? 0;
      return xPatch > yPatch;
    }
    
    function getSatisfyingVersion(
      versions: string[],
      range: string
    ): string | null {
      return versions.find((version) => equals(version, range)) ? range : null;
    }
    
    function minSatisfyingVersion(
      versions: string[],
      range: string
    ): string | null {
      return getSatisfyingVersion(versions, range);
    }
    
    function getNewValue({
      currentValue,
      rangeStrategy,
      currentVersion,
      newVersion,
    }: NewValueConfig): string {
      if (di.isCodename(currentValue)) {
        return di.getCodenameByVersion(newVersion);
      }
      return di.getVersionByCodename(newVersion);
    }
    
    function sortVersions(version: string, other: string): number {
      if (equals(version, other)) {
        return 0;
      }
      if (isGreaterThan(version, other)) {
        return 1;
      }
      return -1;
    }
    
    function matches(version: string, range: string): boolean {
      return equals(version, range);
    }
    
    export const api: VersioningApi = {
      isCompatible,
      isSingleVersion,
      isStable,
      isValid,
      isVersion,
    
      getMajor,
      getMinor,
      getPatch,
    
      equals,
      isGreaterThan,
      getSatisfyingVersion,
      minSatisfyingVersion,
      getNewValue,
      sortVersions,
    
      matches,
    };
    
    export default api;