From e14f09d75b9635ab56257eddbdcb98fc7a5b39c9 Mon Sep 17 00:00:00 2001
From: t-kulmburg <89128736+t-kulmburg@users.noreply.github.com>
Date: Tue, 27 Sep 2022 15:19:18 +0200
Subject: [PATCH] feat(replacement): datasource changes (#17881)

Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 lib/modules/datasource/index.spec.ts | 28 +++++++++++++++++++++++++++-
 lib/modules/datasource/index.ts      |  3 ++-
 lib/modules/datasource/types.ts      |  1 +
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lib/modules/datasource/index.spec.ts b/lib/modules/datasource/index.spec.ts
index f5e911dd48..3580453fd6 100644
--- a/lib/modules/datasource/index.spec.ts
+++ b/lib/modules/datasource/index.spec.ts
@@ -8,7 +8,12 @@ import { ExternalHostError } from '../../types/errors/external-host-error';
 import { loadModules } from '../../util/modules';
 import datasources from './api';
 import { Datasource } from './datasource';
-import type { DatasourceApi, GetReleasesConfig, ReleaseResult } from './types';
+import type {
+  DatasourceApi,
+  DigestConfig,
+  GetReleasesConfig,
+  ReleaseResult,
+} from './types';
 import {
   getDatasourceList,
   getDatasources,
@@ -228,6 +233,27 @@ describe('modules/datasource/index', () => {
       expect(supportsDigests(datasource)).toBeTrue();
       expect(await getDigest({ datasource, depName })).toBe('123');
     });
+
+    it('returns replacementName if defined', async () => {
+      class TestDatasource extends DummyDatasource {
+        override getDigest(
+          config: DigestConfig,
+          newValue?: string
+        ): Promise<string> {
+          return Promise.resolve(config.packageName);
+        }
+      }
+      datasources.set(datasource, new TestDatasource());
+
+      expect(
+        await getDigest({
+          datasource: datasource,
+          packageName: 'pkgName',
+          depName: depName,
+          replacementName: 'replacement',
+        })
+      ).toBe('replacement');
+    });
   });
 
   describe('Metadata', () => {
diff --git a/lib/modules/datasource/index.ts b/lib/modules/datasource/index.ts
index c3472be9ab..7cba3f147d 100644
--- a/lib/modules/datasource/index.ts
+++ b/lib/modules/datasource/index.ts
@@ -433,7 +433,8 @@ function getDigestConfig(
   config: GetDigestInputConfig
 ): DigestConfig {
   const { currentValue, currentDigest } = config;
-  const packageName = config.packageName ?? config.depName;
+  const packageName =
+    config.replacementName ?? config.packageName ?? config.depName;
   const [registryUrl] = resolveRegistryUrls(
     datasource,
     config.defaultRegistryUrls,
diff --git a/lib/modules/datasource/types.ts b/lib/modules/datasource/types.ts
index 6fde73ae3f..054a68e64d 100644
--- a/lib/modules/datasource/types.ts
+++ b/lib/modules/datasource/types.ts
@@ -9,6 +9,7 @@ export interface GetDigestInputConfig {
   additionalRegistryUrls?: string[];
   currentValue?: string;
   currentDigest?: string;
+  replacementName?: string;
 }
 
 export interface DigestConfig {
-- 
GitLab