Skip to content
Snippets Groups Projects
Select Git revision
  • adccb9c0ca838820eaed4374c16d7a877de7b279
  • main default protected
  • next
  • renovate/main-redis-5.x
  • chore/update-static-data
  • feat/gnupg
  • 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
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.62.4
  • 41.62.3
  • 41.62.2
  • 41.62.1
  • 41.62.0
  • 41.61.1
  • 41.61.0
  • 41.60.4
  • 41.60.3
  • 41.60.2
  • 41.60.1
  • 41.60.0
  • 41.59.2
  • 41.59.1
  • 41.59.0
  • 41.58.2
  • 41.58.1
  • 41.58.0
  • 41.57.1
  • 41.57.0
41 results

extract.ts

Blame
  • index.ts 3.28 KiB
    import type { RangeStrategy } from '../../../types';
    import { DistroInfo } from '../distro';
    import { GenericVersioningApi } from '../generic';
    import type { GenericVersion } from '../generic';
    import type { NewValueConfig, VersioningApi } from '../types';
    import { RollingReleasesData } from './common';
    
    export const id = 'debian';
    export const displayName = 'Debian';
    export const urls = [
      'https://debian.pages.debian.net/distro-info-data/debian.csv',
    ];
    export const supportsRanges = true;
    export const supportedRangeStrategies: RangeStrategy[] = ['pin'];
    
    const RELEASE_PROP = 'release';
    
    export class DebianVersioningApi extends GenericVersioningApi {
      private readonly _distroInfo: DistroInfo;
      private readonly _rollingReleases: RollingReleasesData;
    
      constructor() {
        super();
        this._distroInfo = new DistroInfo('data/debian-distro-info.json');
        this._rollingReleases = new RollingReleasesData(this._distroInfo);
      }
    
      override isValid(version: string): boolean {
        const isValid = super.isValid(version);
        const schedule = this._distroInfo.getSchedule(
          this._rollingReleases.getVersionByLts(version),
        );
        return isValid && schedule !== null && RELEASE_PROP in schedule;
      }
    
      override isStable(version: string): boolean {
        let ver: string;
        ver = this._rollingReleases.getVersionByLts(version);
        ver = this._distroInfo.getVersionByCodename(ver);
        return this._distroInfo.isReleased(ver) && !this._distroInfo.isEolLts(ver);
      }
    
      override getNewValue({
        currentValue,
        rangeStrategy,
        newVersion,
      }: NewValueConfig): string {
        if (rangeStrategy === 'pin') {
          let newVer = newVersion;
    
          // convert newVersion to semVer
          if (this._distroInfo.isCodename(newVersion)) {
            newVer = this._distroInfo.getVersionByCodename(newVersion);
          }
          if (this._rollingReleases.has(newVersion)) {
            newVer = this._rollingReleases.getVersionByLts(newVersion);
          }
    
          // current value is codename or [oldold|old|]stable
          if (
            this._distroInfo.isCodename(currentValue) ||
            this._rollingReleases.has(currentValue)
          ) {
            return newVer;
          }
        }
    
        // current value is [oldold|old|]stable
        if (this._rollingReleases.has(currentValue)) {
          return this._rollingReleases.getLtsByVersion(newVersion);
        }
    
        if (this._distroInfo.isCodename(currentValue)) {
          const di = this._rollingReleases.schedule(newVersion);
          let ver = newVersion;
          if (di) {
            ver = di.version;
          }
          return this._distroInfo.getCodenameByVersion(ver);
        }
    
        // newVersion is [oldold|old|]stable
        // current value is numeric
        if (this._rollingReleases.has(newVersion)) {
          return (
            this._rollingReleases.schedule(newVersion)?.version ??
            /* istanbul ignore next: should never happen */ newVersion
          );
        }
    
        return this._distroInfo.getVersionByCodename(newVersion);
      }
    
      protected override _parse(version: string): GenericVersion | null {
        let ver: string;
        ver = this._rollingReleases.getVersionByLts(version);
        ver = this._distroInfo.getVersionByCodename(ver);
        if (!this._distroInfo.exists(ver)) {
          return null;
        }
        return { release: ver.split('.').map(Number) };
      }
    }
    
    export const api: VersioningApi = new DebianVersioningApi();
    
    export default api;