From b6fb8221e171698579ade0559ddec23745a561fd Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Thu, 14 Nov 2024 19:53:00 +0100 Subject: [PATCH 1/3] feat(worker): Use replacement from datasource Fixes #5667 --- .../repository/process/lookup/index.spec.ts | 23 +++++++++++++++++++ .../repository/process/lookup/index.ts | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/lib/workers/repository/process/lookup/index.spec.ts b/lib/workers/repository/process/lookup/index.spec.ts index 986d8bc395..26e13ba8e4 100644 --- a/lib/workers/repository/process/lookup/index.spec.ts +++ b/lib/workers/repository/process/lookup/index.spec.ts @@ -4947,6 +4947,29 @@ describe('workers/repository/process/lookup/index', () => { ]); }); + it('handles replacements - from datasource', async () => { + config.currentValue = '2.0.0'; + config.packageName = 'org.example:foo'; + config.datasource = MavenDatasource.id; + getMavenReleases.mockResolvedValueOnce({ + releases: [{ version: '2.0.0' }], + replacementName: 'foo:bar', + replacementVersion: '2.0.0', + }); + + const { updates } = await Result.wrap( + lookup.lookupUpdates(config), + ).unwrapOrThrow(); + + expect(updates).toEqual([ + { + updateType: 'replacement', + newName: 'foo:bar', + newValue: '2.0.0', + }, + ]); + }); + it('rollback for invalid version to last stable version', async () => { config.currentValue = '2.5.17'; config.packageName = 'vue'; diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index ea4b77b968..4103e18d56 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -569,6 +569,12 @@ export async function lookupUpdates( if (isReplacementRulesConfigured(config)) { addReplacementUpdateIfValid(res.updates, config); + } else if (dependency?.replacementName || dependency?.replacementVersion) { + res.updates.push({ + updateType: 'replacement', + newName: dependency.replacementName, + newValue: dependency.replacementVersion, + }); } // Record if the dep is fixed to a version From 7cc4b9ec58d3cca103391c64bdd249f9cefefa4a Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Thu, 21 Nov 2024 22:34:54 +0100 Subject: [PATCH 2/3] Apply review suggestions --- lib/workers/repository/process/lookup/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 4103e18d56..1e4150c78d 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -569,7 +569,7 @@ export async function lookupUpdates( if (isReplacementRulesConfigured(config)) { addReplacementUpdateIfValid(res.updates, config); - } else if (dependency?.replacementName || dependency?.replacementVersion) { + } else if (dependency?.replacementName && dependency?.replacementVersion) { res.updates.push({ updateType: 'replacement', newName: dependency.replacementName, From d12dab528ae99447473171cdf7f772a8f6121b04 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 18 Dec 2024 06:12:31 +0100 Subject: [PATCH 3/3] Update lib/workers/repository/process/lookup/index.ts Co-authored-by: Michael Kriese --- lib/workers/repository/process/lookup/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 4d2f566474..7c674c8008 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -571,7 +571,7 @@ export async function lookupUpdates( if (isReplacementRulesConfigured(config)) { addReplacementUpdateIfValid(res.updates, config); - } else if (dependency?.replacementName && dependency?.replacementVersion) { + } else if (dependency?.replacementName && dependency.replacementVersion) { res.updates.push({ updateType: 'replacement', newName: dependency.replacementName,