From 7f3b76b5ca31e23c25b97082b6482b4f35cdbb59 Mon Sep 17 00:00:00 2001
From: "M.P. Korstanje" <mpkorstanje@users.noreply.github.com>
Date: Thu, 30 Jan 2025 09:30:46 +0100
Subject: [PATCH] fix(manager/custom): Support range strategy with custom
 managers (#33800)

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
---
 lib/modules/manager/index.spec.ts | 33 ++++++++++++++++++++++++++++++-
 lib/modules/manager/index.ts      |  7 +++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/lib/modules/manager/index.spec.ts b/lib/modules/manager/index.spec.ts
index 1c635b82ff..96411f363a 100644
--- a/lib/modules/manager/index.spec.ts
+++ b/lib/modules/manager/index.spec.ts
@@ -170,7 +170,7 @@ describe('modules/manager/index', () => {
   });
 
   describe('getRangeStrategy', () => {
-    it('returns null', () => {
+    it('returns null for a unknown manager', () => {
       manager.getManagers().set('dummy', {
         defaultConfig: {},
         supportedDatasources: [],
@@ -180,6 +180,37 @@ describe('modules/manager/index', () => {
       ).toBeNull();
     });
 
+    it('returns null for a undefined manager', () => {
+      manager.getManagers().set('dummy', {
+        defaultConfig: {},
+        supportedDatasources: [],
+      });
+      expect(manager.getRangeStrategy({ rangeStrategy: 'auto' })).toBeNull();
+    });
+
+    it('returns non-null for a custom manager', () => {
+      customManager.getCustomManagers().set('dummy', {
+        defaultConfig: {},
+        supportedDatasources: [],
+      });
+      expect(
+        manager.getRangeStrategy({ manager: 'dummy', rangeStrategy: 'auto' }),
+      ).not.toBeNull();
+    });
+
+    it('handles custom managers', () => {
+      customManager.getCustomManagers().set('dummy', {
+        defaultConfig: {},
+        supportedDatasources: [],
+        // For completeness. Custom managers are configured in json and can not
+        // provide a range strategy (yet) but the interface allows for it.
+        getRangeStrategy: () => 'bump',
+      });
+      expect(
+        manager.getRangeStrategy({ manager: 'dummy', rangeStrategy: 'auto' }),
+      ).toBe('bump');
+    });
+
     it('returns non-null', () => {
       manager.getManagers().set('dummy', {
         defaultConfig: {},
diff --git a/lib/modules/manager/index.ts b/lib/modules/manager/index.ts
index e4f9eace29..38a80e5c21 100644
--- a/lib/modules/manager/index.ts
+++ b/lib/modules/manager/index.ts
@@ -78,10 +78,13 @@ export function extractPackageFile(
 
 export function getRangeStrategy(config: RangeConfig): RangeStrategy | null {
   const { manager, rangeStrategy } = config;
-  if (!manager || !managers.has(manager)) {
+  if (!manager) {
+    return null;
+  }
+  const m = managers.get(manager) ?? customManagers.get(manager);
+  if (!m) {
     return null;
   }
-  const m = managers.get(manager)!;
   if (m.getRangeStrategy) {
     // Use manager's own function if it exists
     const managerRangeStrategy = m.getRangeStrategy(config);
-- 
GitLab