0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 21:48:32 +00:00
renovatebot_renovate/lib/modules/versioning/debian/common.ts
Gabriel-Ladzaretti c17a274de3
feat(versioning/debian): Debian codenames support (#14881)
* refactor(tools/distro-info): for later use in ubuntu and debian versioning

cr changes

* feat(versioning/debian): Debian codenames support

restore extracted code

* feat(versioning/debian): Debian codenames support

package.json, dropped the generate: prefix.

unit test mod as per CR

* feat(versioning/debian): Debian codenames support

now using the generic ver api interface

* feat(versioning/debian): Debian codenames support

revert exporting docker versioning

* feat(versioning/debian): Debian codenames support

switched to luxon for time handle
test fixes
dropped ts-ignore comments

* feat(versioning/debian): Debian codenames support

extract changes in distro.ts

* feat(versioning/debian): Debian codenames support

post merge changes

* feat(versioning/debian): Debian codenames support

cr changes

* feat(versioning/debian): Debian codenames support

 - added support for pin range strategy

* feat(versioning/debian): Debian codenames support

- typos & metadata fixes

* feat(versioning/debian): Debian codenames support

- added isReleased to distro.ts

* feat(versioning/debian): Debian codenames support

- moved all time/date handling into distro.ts

- date freeze for ubuntu/debian/distro unit tests

* refactor(versioning/distro): Move date handling into distro.ts

- revert refactor #15272

* feat(versioning/debian): Debian codenames support

 - merge distro refactor

* feat(versioning/debian): Debian codenames support

 - extract private properties

* feat(versioning/debian): Debian codenames support

  - cr changes

* feat(versioning/debian): Debian codenames support

  - cr changes

* feat(versioning/debian): Debian codenames support

  - cr changes

Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-05-18 15:32:59 +00:00

78 lines
1.9 KiB
TypeScript

import { DateTime } from 'luxon';
import { logger } from '../../../logger';
import type { DistroInfo, DistroInfoRecordWithVersion } from '../distro';
const refreshInterval = { days: 1 };
export class RollingReleasesData {
private ltsToVer = new Map<string, DistroInfoRecordWithVersion>();
private verToLts = new Map<string, DistroInfoRecordWithVersion>();
private timestamp = DateTime.fromMillis(0).toUTC(); // start of epoch
private distroInfo: DistroInfo;
constructor(distroInfo: DistroInfo) {
this.distroInfo = distroInfo;
}
getVersionByLts(input: string): string {
this.build();
const schedule = this.ltsToVer.get(input);
if (schedule) {
return schedule.version;
}
return input;
}
getLtsByVersion(input: string): string {
this.build();
const di = this.verToLts.get(input);
if (di) {
return di.series;
}
return input;
}
has(version: string): boolean {
this.build();
return this.ltsToVer.has(version);
}
schedule(version: string): DistroInfoRecordWithVersion | undefined {
this.build();
let schedule: DistroInfoRecordWithVersion | undefined = undefined;
if (this.verToLts.has(version)) {
schedule = this.verToLts.get(version);
}
if (this.ltsToVer.has(version)) {
schedule = this.ltsToVer.get(version);
}
return schedule;
}
private build(): void {
const now = DateTime.now().toUTC();
if (now < this.timestamp.plus(refreshInterval)) {
return;
}
logger.debug('RollingReleasesData - data written');
this.timestamp = now;
for (let i = 0; i < 3; i++) {
const di = this.distroInfo.getNLatest(i);
// istanbul ignore if: should never happen
if (!di) {
return;
}
let prefix = '';
for (let j = 0; j < i; j++) {
prefix += 'old';
}
di.series = prefix + 'stable';
this.ltsToVer.set(di.series, di);
this.verToLts.set(di.version, di);
}
}
}