From c4d46585698775d215f342ea76112fb8581f99c2 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 8 Oct 2024 17:24:46 +0200 Subject: [PATCH] chore: ensure versioning/versioningApi used consistently (#31856) --- lib/util/exec/containerbase.ts | 6 +- lib/util/exec/docker/index.ts | 30 ++++---- lib/util/package-rules/current-version.ts | 14 ++-- lib/workers/repository/init/vulnerability.ts | 6 +- .../repository/process/lookup/bucket.ts | 12 ++-- .../repository/process/lookup/current.ts | 18 ++--- .../process/lookup/filter-checks.ts | 4 +- .../repository/process/lookup/filter.ts | 51 +++++++------- .../repository/process/lookup/generate.ts | 16 ++--- .../repository/process/lookup/index.ts | 70 ++++++++++--------- .../repository/process/lookup/rollback.ts | 18 ++--- .../repository/process/lookup/update-type.ts | 12 +++- .../repository/process/lookup/utils.ts | 4 +- .../repository/update/pr/changelog/index.ts | 4 +- .../update/pr/changelog/releases.ts | 16 +++-- .../repository/update/pr/changelog/source.ts | 38 ++++++---- 16 files changed, 177 insertions(+), 142 deletions(-) diff --git a/lib/util/exec/containerbase.ts b/lib/util/exec/containerbase.ts index 4f54c4879a572e..b0cdd7bd4bde9a 100644 --- a/lib/util/exec/containerbase.ts +++ b/lib/util/exec/containerbase.ts @@ -259,14 +259,14 @@ export function isDynamicInstall( function isStable( version: string, - versioning: allVersioning.VersioningApi, + versioningApi: allVersioning.VersioningApi, latest?: string, ): boolean { - if (!versioning.isStable(version)) { + if (!versioningApi.isStable(version)) { return false; } if (is.string(latest)) { - if (versioning.isGreaterThan(version, latest)) { + if (versioningApi.isGreaterThan(version, latest)) { return false; } } diff --git a/lib/util/exec/docker/index.ts b/lib/util/exec/docker/index.ts index 24d94f8b05cdc6..67728a5bcac667 100644 --- a/lib/util/exec/docker/index.ts +++ b/lib/util/exec/docker/index.ts @@ -3,7 +3,7 @@ import { GlobalConfig } from '../../../config/global'; import { SYSTEM_INSUFFICIENT_MEMORY } from '../../../constants/error-messages'; import { logger } from '../../../logger'; import { getPkgReleases } from '../../../modules/datasource'; -import * as versioning from '../../../modules/versioning'; +import * as allVersioning from '../../../modules/versioning'; import { newlineRegex, regEx } from '../../regex'; import { uniq } from '../../uniq'; import { rawExec } from '../common'; @@ -76,41 +76,45 @@ function prepareCommands(commands: Opt[]): string[] { export async function getDockerTag( packageName: string, constraint: string, - scheme: string, + versioning: string, ): Promise { - const ver = versioning.get(scheme); + const versioningApi = allVersioning.get(versioning); - if (!ver.isValid(constraint)) { + if (!versioningApi.isValid(constraint)) { logger.warn( - { scheme, constraint }, + { versioning, constraint }, `Invalid Docker image version constraint`, ); return 'latest'; } logger.debug( - { packageName, scheme, constraint }, + { packageName, versioning, constraint }, `Found version constraint - checking for a compatible image to use`, ); const imageReleases = await getPkgReleases({ datasource: 'docker', packageName, - versioning: scheme, + versioning, }); if (imageReleases?.releases) { let versions = imageReleases.releases.map((release) => release.version); versions = versions.filter( - (version) => ver.isVersion(version) && ver.matches(version, constraint), + (version) => + versioningApi.isVersion(version) && + versioningApi.matches(version, constraint), ); // Prefer stable versions over unstable, even if the range satisfies both types - if (!versions.every((version) => ver.isStable(version))) { + if (!versions.every((version) => versioningApi.isStable(version))) { logger.debug('Filtering out unstable versions'); - versions = versions.filter((version) => ver.isStable(version)); + versions = versions.filter((version) => versioningApi.isStable(version)); } - const version = versions.sort(ver.sortVersions.bind(ver)).pop(); + const version = versions + .sort(versioningApi.sortVersions.bind(versioningApi)) + .pop(); if (version) { logger.debug( - { packageName, scheme, constraint, version }, + { packageName, versioning, constraint, version }, `Found compatible image version`, ); return version; @@ -120,7 +124,7 @@ export async function getDockerTag( return 'latest'; } logger.warn( - { packageName, constraint, scheme }, + { packageName, constraint, versioning }, 'Failed to find a tag satisfying constraint, using "latest" tag instead', ); return 'latest'; diff --git a/lib/util/package-rules/current-version.ts b/lib/util/package-rules/current-version.ts index 9cbae8d57cc43f..62106041e7a7f8 100644 --- a/lib/util/package-rules/current-version.ts +++ b/lib/util/package-rules/current-version.ts @@ -20,7 +20,7 @@ export class CurrentVersionMatcher extends Matcher { } const isUnconstrainedValue = !!lockedVersion && is.nullOrUndefined(currentValue); - const version = allVersioning.get(versioning); + const versioningApi = allVersioning.get(versioning); const matchCurrentVersionStr = matchCurrentVersion.toString(); const matchCurrentVersionPred = getRegexPredicate(matchCurrentVersionStr); @@ -31,14 +31,14 @@ export class CurrentVersionMatcher extends Matcher { matchCurrentVersionPred(compareVersion) ); } - if (version.isVersion(matchCurrentVersionStr)) { + if (versioningApi.isVersion(matchCurrentVersionStr)) { try { return ( isUnconstrainedValue || !!( currentValue && - version.isValid(currentValue) && - version.matches(matchCurrentVersionStr, currentValue) + versioningApi.isValid(currentValue) && + versioningApi.matches(matchCurrentVersionStr, currentValue) ) ); } catch { @@ -46,14 +46,14 @@ export class CurrentVersionMatcher extends Matcher { } } - const compareVersion = version.isVersion(currentValue) + const compareVersion = versioningApi.isVersion(currentValue) ? currentValue // it's a version so we can match against it : (lockedVersion ?? currentVersion); // need to match against this currentVersion, if available if (is.nullOrUndefined(compareVersion)) { return false; } - if (version.isVersion(compareVersion)) { - return version.matches(compareVersion, matchCurrentVersion); + if (versioningApi.isVersion(compareVersion)) { + return versioningApi.matches(compareVersion, matchCurrentVersion); } logger.debug( { matchCurrentVersionStr, currentValue }, diff --git a/lib/workers/repository/init/vulnerability.ts b/lib/workers/repository/init/vulnerability.ts index 4b6b801589362d..8c8c06bfbb8510 100644 --- a/lib/workers/repository/init/vulnerability.ts +++ b/lib/workers/repository/init/vulnerability.ts @@ -120,11 +120,11 @@ export async function detectVulnerabilityAlerts( }; const alertDetails = combinedAlerts[fileName][datasource][depName]; alertDetails.advisories.push(advisory); - const version = allVersioning.get(versionings[datasource]); - if (version.isVersion(firstPatchedVersion)) { + const versioningApi = allVersioning.get(versionings[datasource]); + if (versioningApi.isVersion(firstPatchedVersion)) { if ( !alertDetails.firstPatchedVersion || - version.isGreaterThan( + versioningApi.isGreaterThan( firstPatchedVersion, alertDetails.firstPatchedVersion, ) diff --git a/lib/workers/repository/process/lookup/bucket.ts b/lib/workers/repository/process/lookup/bucket.ts index b54b70ab99d8ea..1854ee0a7a62c4 100644 --- a/lib/workers/repository/process/lookup/bucket.ts +++ b/lib/workers/repository/process/lookup/bucket.ts @@ -11,7 +11,7 @@ export function getBucket( config: BucketConfig, currentVersion: string, newVersion: string, - versioning: VersioningApi, + versioningApi: VersioningApi, ): string | null { const { separateMajorMinor, @@ -22,8 +22,8 @@ export function getBucket( if (!separateMajorMinor) { return 'latest'; } - const fromMajor = versioning.getMajor(currentVersion); - const toMajor = versioning.getMajor(newVersion); + const fromMajor = versioningApi.getMajor(currentVersion); + const toMajor = versioningApi.getMajor(newVersion); // istanbul ignore if: error case if (toMajor === null) { @@ -41,8 +41,8 @@ export function getBucket( // If we reach here then we know it's non-major - const fromMinor = versioning.getMinor(currentVersion); - const toMinor = versioning.getMinor(newVersion); + const fromMinor = versioningApi.getMinor(currentVersion); + const toMinor = versioningApi.getMinor(newVersion); // istanbul ignore if: error case if (fromMinor === null || toMinor === null) { @@ -66,7 +66,7 @@ export function getBucket( /* future option if (separateMultiplePatch) { - const toPatch = versioning.getPatch(newVersion); + const toPatch = versioningApi.getPatch(newVersion); if (toPatch !== null && separateMultiplePatch) { return `v${toMajor}.${toMinor}.${toPatch}`; } diff --git a/lib/workers/repository/process/lookup/current.ts b/lib/workers/repository/process/lookup/current.ts index cd37363c50441f..4828052035aafd 100644 --- a/lib/workers/repository/process/lookup/current.ts +++ b/lib/workers/repository/process/lookup/current.ts @@ -6,7 +6,7 @@ import { regEx } from '../../../../util/regex'; export function getCurrentVersion( currentValue: string, lockedVersion: string, - versioning: VersioningApi, + versioningApi: VersioningApi, rangeStrategy: string, latestVersion: string, allVersions: string[], @@ -20,28 +20,28 @@ export function getCurrentVersion( return currentValue; } let useVersions = allVersions.filter((v) => - versioning.matches(v, currentValue), + versioningApi.matches(v, currentValue), ); if (useVersions.length === 1) { return useVersions[0]; } - if (latestVersion && versioning.matches(latestVersion, currentValue)) { + if (latestVersion && versioningApi.matches(latestVersion, currentValue)) { useVersions = useVersions.filter( - (v) => !versioning.isGreaterThan(v, latestVersion), + (v) => !versioningApi.isGreaterThan(v, latestVersion), ); } if (rangeStrategy === 'pin') { return ( lockedVersion || - versioning.getSatisfyingVersion(useVersions, currentValue) + versioningApi.getSatisfyingVersion(useVersions, currentValue) ); } if (rangeStrategy === 'bump') { // Use the lowest version in the current range - return versioning.minSatisfyingVersion(useVersions, currentValue); + return versioningApi.minSatisfyingVersion(useVersions, currentValue); } // Use the highest version in the current range - const satisfyingVersion = versioning.getSatisfyingVersion( + const satisfyingVersion = versioningApi.getSatisfyingVersion( useVersions, currentValue, ); @@ -49,10 +49,10 @@ export function getCurrentVersion( return satisfyingVersion; } - if (versioning.isVersion(currentValue)) { + if (versioningApi.isVersion(currentValue)) { return currentValue; } - if (versioning.isSingleVersion(currentValue)) { + if (versioningApi.isSingleVersion(currentValue)) { return currentValue.replace(regEx(/=/g), '').trim(); } diff --git a/lib/workers/repository/process/lookup/filter-checks.ts b/lib/workers/repository/process/lookup/filter-checks.ts index fc52ce2cf25ed2..9bac9c4bef69c8 100644 --- a/lib/workers/repository/process/lookup/filter-checks.ts +++ b/lib/workers/repository/process/lookup/filter-checks.ts @@ -24,7 +24,7 @@ export interface InternalChecksResult { export async function filterInternalChecks( config: Partial, - versioning: VersioningApi, + versioningApi: VersioningApi, bucket: string, sortedReleases: Release[], ): Promise { @@ -43,7 +43,7 @@ export async function filterInternalChecks( // calculate updateType and then apply it releaseConfig.updateType = getUpdateType( releaseConfig, - versioning, + versioningApi, // TODO #22198 currentVersion!, candidateRelease.version, diff --git a/lib/workers/repository/process/lookup/filter.ts b/lib/workers/repository/process/lookup/filter.ts index 7c2bd0aa2619be..fc800b96c6ddc3 100644 --- a/lib/workers/repository/process/lookup/filter.ts +++ b/lib/workers/repository/process/lookup/filter.ts @@ -9,8 +9,11 @@ import * as poetryVersioning from '../../../../modules/versioning/poetry'; import { getRegexPredicate } from '../../../../util/string-match'; import type { FilterConfig } from './types'; -function isReleaseStable(release: Release, versioning: VersioningApi): boolean { - if (!versioning.isStable(release.version)) { +function isReleaseStable( + release: Release, + versioningApi: VersioningApi, +): boolean { + if (!versioningApi.isStable(release.version)) { return false; } @@ -26,7 +29,7 @@ export function filterVersions( currentVersion: string, latestVersion: string, releases: Release[], - versioning: VersioningApi, + versioningApi: VersioningApi, ): Release[] { const { ignoreUnstable, ignoreDeprecated, respectLatest, allowedVersions } = config; @@ -39,17 +42,17 @@ export function filterVersions( // Leave only versions greater than current let filteredReleases = releases.filter( (r) => - versioning.isVersion(r.version) && - versioning.isGreaterThan(r.version, currentVersion), + versioningApi.isVersion(r.version) && + versioningApi.isGreaterThan(r.version, currentVersion), ); const currentRelease = releases.find( (r) => - versioning.isValid(r.version) && - versioning.isVersion(r.version) && - versioning.isValid(currentVersion) && - versioning.isVersion(currentVersion) && - versioning.equals(r.version, currentVersion), + versioningApi.isValid(r.version) && + versioningApi.isVersion(r.version) && + versioningApi.isValid(currentVersion) && + versioningApi.isVersion(currentVersion) && + versioningApi.equals(r.version, currentVersion), ); // Don't upgrade from non-deprecated to deprecated @@ -71,9 +74,9 @@ export function filterVersions( filteredReleases = filteredReleases.filter(({ version }) => isAllowedPred(version), ); - } else if (versioning.isValid(allowedVersions)) { + } else if (versioningApi.isValid(allowedVersions)) { filteredReleases = filteredReleases.filter((r) => - versioning.matches(r.version, allowedVersions), + versioningApi.matches(r.version, allowedVersions), ); } else if ( config.versioning !== npmVersioning.id && @@ -122,10 +125,10 @@ export function filterVersions( if ( respectLatest && latestVersion && - !versioning.isGreaterThan(currentVersion, latestVersion) + !versioningApi.isGreaterThan(currentVersion, latestVersion) ) { filteredReleases = filteredReleases.filter( - (r) => !versioning.isGreaterThan(r.version, latestVersion), + (r) => !versioningApi.isGreaterThan(r.version, latestVersion), ); } @@ -133,31 +136,31 @@ export function filterVersions( return filteredReleases; } - if (currentRelease && isReleaseStable(currentRelease, versioning)) { - return filteredReleases.filter((r) => isReleaseStable(r, versioning)); + if (currentRelease && isReleaseStable(currentRelease, versioningApi)) { + return filteredReleases.filter((r) => isReleaseStable(r, versioningApi)); } - const currentMajor = versioning.getMajor(currentVersion); - const currentMinor = versioning.getMinor(currentVersion); - const currentPatch = versioning.getPatch(currentVersion); + const currentMajor = versioningApi.getMajor(currentVersion); + const currentMinor = versioningApi.getMinor(currentVersion); + const currentPatch = versioningApi.getPatch(currentVersion); return filteredReleases.filter((r) => { - if (isReleaseStable(r, versioning)) { + if (isReleaseStable(r, versioningApi)) { return true; } - const major = versioning.getMajor(r.version); + const major = versioningApi.getMajor(r.version); if (major !== currentMajor) { return false; } - if (versioning.allowUnstableMajorUpgrades) { + if (versioningApi.allowUnstableMajorUpgrades) { return true; } - const minor = versioning.getMinor(r.version); - const patch = versioning.getPatch(r.version); + const minor = versioningApi.getMinor(r.version); + const patch = versioningApi.getPatch(r.version); return minor === currentMinor && patch === currentPatch; }); diff --git a/lib/workers/repository/process/lookup/generate.ts b/lib/workers/repository/process/lookup/generate.ts index 3a352be8a5395f..5946a5e3a620ea 100644 --- a/lib/workers/repository/process/lookup/generate.ts +++ b/lib/workers/repository/process/lookup/generate.ts @@ -11,7 +11,7 @@ import { getUpdateType } from './update-type'; export async function generateUpdate( config: LookupUpdateConfig, currentValue: string | undefined, - versioning: VersioningApi, + versioningApi: VersioningApi, rangeStrategy: RangeStrategy, currentVersion: string, bucket: string, @@ -52,7 +52,7 @@ export async function generateUpdate( if (currentValue) { try { - update.newValue = versioning.getNewValue({ + update.newValue = versioningApi.getNewValue({ currentValue, rangeStrategy, currentVersion, @@ -68,9 +68,9 @@ export async function generateUpdate( } else { update.newValue = currentValue; } - update.newMajor = versioning.getMajor(newVersion)!; - update.newMinor = versioning.getMinor(newVersion)!; - update.newPatch = versioning.getPatch(newVersion)!; + update.newMajor = versioningApi.getMajor(newVersion)!; + update.newMinor = versioningApi.getMinor(newVersion)!; + update.newPatch = versioningApi.getPatch(newVersion)!; // istanbul ignore if if (!update.updateType && !currentVersion) { logger.debug({ update }, 'Update has no currentVersion'); @@ -79,7 +79,7 @@ export async function generateUpdate( } update.updateType = update.updateType ?? - getUpdateType(config, versioning, currentVersion, newVersion); + getUpdateType(config, versioningApi, currentVersion, newVersion); const { datasource, packageName, packageRules } = config; if (packageRules?.some((pr) => is.nonEmptyArray(pr.matchConfidence))) { update.mergeConfidenceLevel = await getMergeConfidenceLevel( @@ -90,7 +90,7 @@ export async function generateUpdate( update.updateType, ); } - if (!versioning.isVersion(update.newValue)) { + if (!versioningApi.isVersion(update.newValue)) { update.isRange = true; } if (rangeStrategy === 'update-lockfile' && currentValue === update.newValue) { @@ -99,7 +99,7 @@ export async function generateUpdate( if ( rangeStrategy === 'bump' && // TODO #22198 - versioning.matches(newVersion, currentValue!) + versioningApi.matches(newVersion, currentValue!) ) { update.isBump = true; } diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index a62734626a798a..c807c25ec37bdd 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -42,11 +42,12 @@ import { function getTimestamp( versions: Release[], version: string, - versioning: allVersioning.VersioningApi, + versioningApi: allVersioning.VersioningApi, ): string | null | undefined { return versions.find( (v) => - versioning.isValid(v.version) && versioning.equals(v.version, version), + versioningApi.isValid(v.version) && + versioningApi.equals(v.version, version), )?.releaseTimestamp; } @@ -56,7 +57,7 @@ export async function lookupUpdates( let config: LookupUpdateConfig = { ...inconfig }; config.versioning ??= getDefaultVersioning(config.datasource); - const versioning = allVersioning.get(config.versioning); + const versioningApi = allVersioning.get(config.versioning); const unconstrainedValue = !!config.lockedVersion && is.undefined(config.currentValue); @@ -122,13 +123,14 @@ export async function lookupUpdates( ); } } - const isValid = is.string(compareValue) && versioning.isValid(compareValue); + const isValid = + is.string(compareValue) && versioningApi.isValid(compareValue); if (unconstrainedValue || isValid) { if ( !config.updatePinnedDependencies && // TODO #22198 - versioning.isSingleVersion(compareValue!) + versioningApi.isSingleVersion(compareValue!) ) { res.skipReason = 'is-pinned'; return Result.ok(res); @@ -185,7 +187,7 @@ export async function lookupUpdates( const latestVersion = dependency.tags?.latest; // Filter out any results from datasource that don't comply with our versioning let allVersions = dependency.releases.filter((release) => - versioning.isVersion(release.version), + versioningApi.isVersion(release.version), ); // istanbul ignore if if (allVersions.length === 0) { @@ -219,14 +221,14 @@ export async function lookupUpdates( (v) => v.version === taggedVersion || (v.version === compareValue && - versioning.isGreaterThan(taggedVersion, compareValue)), + versioningApi.isGreaterThan(taggedVersion, compareValue)), ); } // Check that existing constraint can be satisfied const allSatisfyingVersions = allVersions.filter( (v) => // TODO #22198 - unconstrainedValue || versioning.matches(v.version, compareValue!), + unconstrainedValue || versioningApi.matches(v.version, compareValue!), ); if (!allSatisfyingVersions.length) { logger.debug( @@ -235,7 +237,7 @@ export async function lookupUpdates( } if (config.rollbackPrs && !allSatisfyingVersions.length) { - const rollback = getRollbackUpdate(config, allVersions, versioning); + const rollback = getRollbackUpdate(config, allVersions, versioningApi); // istanbul ignore if if (!rollback) { res.warnings.push({ @@ -279,7 +281,7 @@ export async function lookupUpdates( getCurrentVersion( compareValue!, config.lockedVersion!, - versioning, + versioningApi, rangeStrategy!, latestVersion!, nonDeprecatedVersions, @@ -287,7 +289,7 @@ export async function lookupUpdates( getCurrentVersion( compareValue!, config.lockedVersion!, - versioning, + versioningApi, rangeStrategy!, latestVersion!, allVersions.map((v) => v.version), @@ -307,7 +309,7 @@ export async function lookupUpdates( const currentVersionTimestamp = getTimestamp( allVersions, currentVersion, - versioning, + versioningApi, ); if (is.nonEmptyString(currentVersionTimestamp)) { @@ -329,20 +331,20 @@ export async function lookupUpdates( compareValue && currentVersion && rangeStrategy === 'pin' && - !versioning.isSingleVersion(compareValue) + !versioningApi.isSingleVersion(compareValue) ) { res.updates.push({ updateType: 'pin', isPin: true, // TODO: newValue can be null! (#22198) - newValue: versioning.getNewValue({ + newValue: versioningApi.getNewValue({ currentValue: compareValue, rangeStrategy, currentVersion, newVersion: currentVersion, })!, newVersion: currentVersion, - newMajor: versioning.getMajor(currentVersion)!, + newMajor: versioningApi.getMajor(currentVersion)!, }); } if (rangeStrategy === 'pin') { @@ -350,7 +352,7 @@ export async function lookupUpdates( rangeStrategy = 'replace'; } // istanbul ignore if - if (!versioning.isVersion(currentVersion!)) { + if (!versioningApi.isVersion(currentVersion!)) { res.skipReason = 'invalid-version'; return Result.ok(res); } @@ -363,25 +365,25 @@ export async function lookupUpdates( config.rangeStrategy === 'in-range-only' ? allSatisfyingVersions : allVersions, - versioning, + versioningApi, ).filter( (v) => // Leave only compatible versions unconstrainedValue || - versioning.isCompatible(v.version, compareValue), + versioningApi.isCompatible(v.version, compareValue), ); let shrinkedViaVulnerability = false; if (config.isVulnerabilityAlert) { if (config.vulnerabilityFixVersion) { res.vulnerabilityFixVersion = config.vulnerabilityFixVersion; res.vulnerabilityFixStrategy = config.vulnerabilityFixStrategy; - if (versioning.isValid(config.vulnerabilityFixVersion)) { + if (versioningApi.isValid(config.vulnerabilityFixVersion)) { let fixedFilteredReleases; - if (versioning.isVersion(config.vulnerabilityFixVersion)) { + if (versioningApi.isVersion(config.vulnerabilityFixVersion)) { // Retain only releases greater than or equal to the fix version fixedFilteredReleases = filteredReleases.filter( (release) => - !versioning.isGreaterThan( + !versioningApi.isGreaterThan( config.vulnerabilityFixVersion!, release.version, ), @@ -389,7 +391,7 @@ export async function lookupUpdates( } else { // Retain only releases which max the fix constraint fixedFilteredReleases = filteredReleases.filter((release) => - versioning.matches( + versioningApi.matches( release.version, config.vulnerabilityFixVersion!, ), @@ -439,7 +441,7 @@ export async function lookupUpdates( // TODO #22198 currentVersion!, release.version, - versioning, + versioningApi, ); if (is.string(bucket)) { if (buckets[bucket]) { @@ -452,12 +454,12 @@ export async function lookupUpdates( const depResultConfig = mergeChildConfig(config, res); for (const [bucket, releases] of Object.entries(buckets)) { const sortedReleases = releases.sort((r1, r2) => - versioning.sortVersions(r1.version, r2.version), + versioningApi.sortVersions(r1.version, r2.version), ); const { release, pendingChecks, pendingReleases } = await filterInternalChecks( depResultConfig, - versioning, + versioningApi, bucket, sortedReleases, ); @@ -469,7 +471,7 @@ export async function lookupUpdates( const update = await generateUpdate( config, compareValue, - versioning, + versioningApi, // TODO #22198 rangeStrategy!, @@ -517,16 +519,16 @@ export async function lookupUpdates( } res.isSingleVersion ??= is.string(update.newValue) && - versioning.isSingleVersion(update.newValue); + versioningApi.isSingleVersion(update.newValue); // istanbul ignore if if ( config.versioning === dockerVersioningId && update.updateType !== 'rollback' && update.newValue && - versioning.isVersion(update.newValue) && + versioningApi.isVersion(update.newValue) && compareValue && - versioning.isVersion(compareValue) && - versioning.isGreaterThan(compareValue, update.newValue) + versioningApi.isVersion(compareValue) && + versioningApi.isGreaterThan(compareValue, update.newValue) ) { logger.warn( { @@ -570,7 +572,7 @@ export async function lookupUpdates( if (config.lockedVersion) { res.currentVersion = config.lockedVersion; res.fixedVersion = config.lockedVersion; - } else if (compareValue && versioning.isSingleVersion(compareValue)) { + } else if (compareValue && versioningApi.isSingleVersion(compareValue)) { res.fixedVersion = compareValue.replace(regEx(/^=+/), ''); } @@ -612,12 +614,12 @@ export async function lookupUpdates( }); } } - if (versioning.valueToVersion) { + if (versioningApi.valueToVersion) { // TODO #22198 - res.currentVersion = versioning.valueToVersion(res.currentVersion!); + res.currentVersion = versioningApi.valueToVersion(res.currentVersion!); for (const update of res.updates || /* istanbul ignore next*/ []) { // TODO #22198 - update.newVersion = versioning.valueToVersion(update.newVersion!); + update.newVersion = versioningApi.valueToVersion(update.newVersion!); } } if (res.registryUrl) { diff --git a/lib/workers/repository/process/lookup/rollback.ts b/lib/workers/repository/process/lookup/rollback.ts index 64a45b7afab5a5..4f6171d25e856c 100644 --- a/lib/workers/repository/process/lookup/rollback.ts +++ b/lib/workers/repository/process/lookup/rollback.ts @@ -7,11 +7,11 @@ import type { RollbackConfig } from './types'; export function getRollbackUpdate( config: RollbackConfig, versions: Release[], - version: VersioningApi, + versioningApi: VersioningApi, ): LookupUpdate | null { const { packageFile, versioning, depName, currentValue } = config; // istanbul ignore if - if (!('isLessThanRange' in version)) { + if (!('isLessThanRange' in versioningApi)) { logger.debug( { versioning }, 'Current versioning does not support isLessThanRange()', @@ -20,7 +20,7 @@ export function getRollbackUpdate( } const lessThanVersions = versions.filter((v) => { try { - return version.isLessThanRange!(v.version, currentValue!); + return versioningApi.isLessThanRange!(v.version, currentValue!); } catch /* istanbul ignore next */ { return false; } @@ -42,11 +42,13 @@ export function getRollbackUpdate( 'Versions found before rolling back', ); - lessThanVersions.sort((a, b) => version.sortVersions(a.version, b.version)); + lessThanVersions.sort((a, b) => + versioningApi.sortVersions(a.version, b.version), + ); let newRelease; - if (currentValue && version.isStable(currentValue)) { + if (currentValue && versioningApi.isStable(currentValue)) { newRelease = lessThanVersions - .filter((v) => version.isStable(v.version)) + .filter((v) => versioningApi.isStable(v.version)) .pop(); } let newVersion = newRelease?.version; @@ -62,7 +64,7 @@ export function getRollbackUpdate( logger.debug('No newVersion to roll back to'); return null; } - const newValue = version.getNewValue({ + const newValue = versioningApi.getNewValue({ // TODO #22198 currentValue: currentValue!, rangeStrategy: 'replace', @@ -71,7 +73,7 @@ export function getRollbackUpdate( return { bucket: 'rollback', // TODO #22198 - newMajor: version.getMajor(newVersion)!, + newMajor: versioningApi.getMajor(newVersion)!, newValue: newValue!, newVersion, registryUrl, diff --git a/lib/workers/repository/process/lookup/update-type.ts b/lib/workers/repository/process/lookup/update-type.ts index 9db72f6a56746e..e919cfd2cbdbaf 100644 --- a/lib/workers/repository/process/lookup/update-type.ts +++ b/lib/workers/repository/process/lookup/update-type.ts @@ -10,14 +10,20 @@ export interface UpdateTypeConfig { export function getUpdateType( config: UpdateTypeConfig, - versioning: allVersioning.VersioningApi, + versioningApi: allVersioning.VersioningApi, currentVersion: string, newVersion: string, ): UpdateType { - if (versioning.getMajor(newVersion)! > versioning.getMajor(currentVersion)!) { + if ( + versioningApi.getMajor(newVersion)! > + versioningApi.getMajor(currentVersion)! + ) { return 'major'; } - if (versioning.getMinor(newVersion)! > versioning.getMinor(currentVersion)!) { + if ( + versioningApi.getMinor(newVersion)! > + versioningApi.getMinor(currentVersion)! + ) { return 'minor'; } return 'patch'; diff --git a/lib/workers/repository/process/lookup/utils.ts b/lib/workers/repository/process/lookup/utils.ts index 9e12201bb3cbfa..cc544cd863b0fb 100644 --- a/lib/workers/repository/process/lookup/utils.ts +++ b/lib/workers/repository/process/lookup/utils.ts @@ -50,11 +50,11 @@ export function determineNewReplacementName( export function determineNewReplacementValue( config: LookupUpdateConfig, ): string | undefined | null { - const versioning = allVersioning.get(config.versioning); + const versioningApi = allVersioning.get(config.versioning); const rangeStrategy = getRangeStrategy(config); if (!is.nullOrUndefined(config.replacementVersion)) { - return versioning.getNewValue({ + return versioningApi.getNewValue({ // TODO #22198 currentValue: config.currentValue!, newVersion: config.replacementVersion, diff --git a/lib/workers/repository/update/pr/changelog/index.ts b/lib/workers/repository/update/pr/changelog/index.ts index d24ea5138b905a..dbe5d30eb697ac 100644 --- a/lib/workers/repository/update/pr/changelog/index.ts +++ b/lib/workers/repository/update/pr/changelog/index.ts @@ -17,8 +17,8 @@ export async function getChangeLogJSON( if (!(sourceUrl && currentVersion && newVersion)) { return null; } - const version = allVersioning.get(versioning); - if (version.equals(currentVersion, newVersion)) { + const versioningApi = allVersioning.get(versioning); + if (versioningApi.equals(currentVersion, newVersion)) { return null; } logger.debug( diff --git a/lib/workers/repository/update/pr/changelog/releases.ts b/lib/workers/repository/update/pr/changelog/releases.ts index 42e5747aab9049..9a9113bd1fcb4e 100644 --- a/lib/workers/repository/update/pr/changelog/releases.ts +++ b/lib/workers/repository/update/pr/changelog/releases.ts @@ -10,20 +10,24 @@ import { get } from '../../../../../modules/versioning'; import { coerceArray } from '../../../../../util/array'; import type { BranchUpgradeConfig } from '../../../../types'; -function matchesMMP(version: VersioningApi, v1: string, v2: string): boolean { +function matchesMMP( + versioningApi: VersioningApi, + v1: string, + v2: string, +): boolean { return ( - version.getMajor(v1) === version.getMajor(v2) && - version.getMinor(v1) === version.getMinor(v2) && - version.getPatch(v1) === version.getPatch(v2) + versioningApi.getMajor(v1) === versioningApi.getMajor(v2) && + versioningApi.getMinor(v1) === versioningApi.getMinor(v2) && + versioningApi.getPatch(v1) === versioningApi.getPatch(v2) ); } function matchesUnstable( - version: VersioningApi, + versioningApi: VersioningApi, v1: string, v2: string, ): boolean { - return !version.isStable(v1) && matchesMMP(version, v1, v2); + return !versioningApi.isStable(v1) && matchesMMP(versioningApi, v1, v2); } export async function getInRangeReleases( diff --git a/lib/workers/repository/update/pr/changelog/source.ts b/lib/workers/repository/update/pr/changelog/source.ts index 0101a00e056edc..ae76f628f5bf4d 100644 --- a/lib/workers/repository/update/pr/changelog/source.ts +++ b/lib/workers/repository/update/pr/changelog/source.ts @@ -76,7 +76,7 @@ export abstract class ChangeLogSource { const packageName = config.packageName!; const depName = config.depName!; const sourceDirectory = config.sourceDirectory; - const version = allVersioning.get(versioning); + const versioningApi = allVersioning.get(versioning); if (this.shouldSkipPackage(config)) { return null; @@ -108,8 +108,8 @@ export abstract class ChangeLogSource { } // This extra filter/sort should not be necessary, but better safe than sorry const validReleases = [...releases] - .filter((release) => version.isVersion(release.version)) - .sort((a, b) => version.sortVersions(a.version, b.version)); + .filter((release) => versioningApi.isVersion(release.version)) + .sort((a, b) => versioningApi.sortVersions(a.version, b.version)); if (validReleases.length < 2) { logger.debug( @@ -122,8 +122,8 @@ export abstract class ChangeLogSource { // Check if `v` belongs to the range (currentVersion, newVersion] const inRange = (v: string): boolean => - version.isGreaterThan(v, currentVersion) && - !version.isGreaterThan(v, newVersion); + versioningApi.isGreaterThan(v, currentVersion) && + !versioningApi.isGreaterThan(v, newVersion); const getTags = memoize(() => this.getAllTags(apiBaseUrl, repository)); for (let i = 1; i < validReleases.length; i += 1) { @@ -146,8 +146,20 @@ export abstract class ChangeLogSource { compare: {}, }; const tags = await getTags(); - const prevHead = this.getRef(version, packageName, depName, prev, tags); - const nextHead = this.getRef(version, packageName, depName, next, tags); + const prevHead = this.getRef( + versioningApi, + packageName, + depName, + prev, + tags, + ); + const nextHead = this.getRef( + versioningApi, + packageName, + depName, + next, + tags, + ); if (is.nonEmptyString(prevHead) && is.nonEmptyString(nextHead)) { release.compare.url = this.getCompareURL( baseUrl, @@ -186,7 +198,7 @@ export abstract class ChangeLogSource { } private findTagOfRelease( - version: allVersioning.VersioningApi, + versioningApi: allVersioning.VersioningApi, packageName: string, depName: string, depNewVersion: string, @@ -200,19 +212,21 @@ export abstract class ChangeLogSource { }); const tagList = exactTagsList.length ? exactTagsList : tags; return tagList - .filter((tag) => version.isVersion(tag.replace(regex, ''))) - .find((tag) => version.equals(tag.replace(regex, ''), depNewVersion)); + .filter((tag) => versioningApi.isVersion(tag.replace(regex, ''))) + .find((tag) => + versioningApi.equals(tag.replace(regex, ''), depNewVersion), + ); } private getRef( - version: allVersioning.VersioningApi, + versioningApi: allVersioning.VersioningApi, packageName: string, depName: string, release: Release, tags: string[], ): string | null { const tagName = this.findTagOfRelease( - version, + versioningApi, packageName, depName, release.version,