From f0c20677986914d0497e2366fb6e2fc48e05a5a5 Mon Sep 17 00:00:00 2001
From: LukasAuerbeck <17929465+LukasAuerbeck@users.noreply.github.com>
Date: Fri, 2 Aug 2024 14:19:14 +0200
Subject: [PATCH] refactor: move onboading repo lookup into dedicated function
 (#30554)

Signed-off-by: LukasAuerbeck <17929465+LukasAuerbeck@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 .../repository/onboarding/branch/config.ts    | 43 +++++++++++--------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/lib/workers/repository/onboarding/branch/config.ts b/lib/workers/repository/onboarding/branch/config.ts
index 5096f42ea9..0d67f9aa67 100644
--- a/lib/workers/repository/onboarding/branch/config.ts
+++ b/lib/workers/repository/onboarding/branch/config.ts
@@ -14,12 +14,33 @@ async function getOnboardingConfig(
 ): Promise<RenovateSharedConfig | undefined> {
   let onboardingConfig = clone(config.onboardingConfig);
 
-  let foundPreset: string | undefined;
+  // TODO #22198 fix types
+  const foundPreset = await searchDefaultOnboardingPreset(config.repository!);
+
+  if (foundPreset) {
+    logger.debug(`Found preset ${foundPreset} - using it in onboarding config`);
+    onboardingConfig = {
+      $schema: 'https://docs.renovatebot.com/renovate-schema.json',
+      extends: [foundPreset],
+    };
+  } else {
+    // Organization preset did not exist
+    logger.debug(
+      'No default org/owner preset found, so the default onboarding config will be used instead.',
+    );
+  }
+
+  logger.debug({ config: onboardingConfig }, 'onboarding config');
+  return onboardingConfig;
+}
 
+async function searchDefaultOnboardingPreset(
+  repository: string,
+): Promise<string | undefined> {
+  let foundPreset: string | undefined;
   logger.debug('Checking for a default Renovate preset which can be used.');
 
-  // TODO #22198
-  const repoPathParts = config.repository!.split('/');
+  const repoPathParts = repository.split('/');
 
   for (
     let index = repoPathParts.length - 1;
@@ -77,21 +98,7 @@ async function getOnboardingConfig(
     }
   }
 
-  if (foundPreset) {
-    logger.debug(`Found preset ${foundPreset} - using it in onboarding config`);
-    onboardingConfig = {
-      $schema: 'https://docs.renovatebot.com/renovate-schema.json',
-      extends: [foundPreset],
-    };
-  } else {
-    // Organization preset did not exist
-    logger.debug(
-      'No default org/owner preset found, so the default onboarding config will be used instead.',
-    );
-  }
-
-  logger.debug({ config: onboardingConfig }, 'onboarding config');
-  return onboardingConfig;
+  return foundPreset;
 }
 
 async function getOnboardingConfigContents(
-- 
GitLab