From ddebfdb715daa3be4cd62ac5506d45a8596cb377 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 29 May 2023 05:57:08 +0200
Subject: [PATCH] refactor: bucket logic (#22464)

---
 .../repository/process/lookup/bucket.ts       | 53 ++++++++++++++++---
 1 file changed, 45 insertions(+), 8 deletions(-)

diff --git a/lib/workers/repository/process/lookup/bucket.ts b/lib/workers/repository/process/lookup/bucket.ts
index 3c50a95f67..ba12098d00 100644
--- a/lib/workers/repository/process/lookup/bucket.ts
+++ b/lib/workers/repository/process/lookup/bucket.ts
@@ -19,23 +19,60 @@ export function getBucket(
   }
   const fromMajor = versioning.getMajor(currentVersion);
   const toMajor = versioning.getMajor(newVersion);
-  // istanbul ignore if
+
+  // istanbul ignore if: error case
   if (toMajor === null) {
     return null;
   }
+
+  // Check for major update type first
   if (fromMajor !== toMajor) {
     if (separateMultipleMajor) {
-      return `major-${toMajor}`;
+      return `v${toMajor}`;
     }
+    // default path for major updates is not to separate them
     return 'major';
   }
-  if (separateMinorPatch) {
-    if (
-      versioning.getMinor(currentVersion) === versioning.getMinor(newVersion)
-    ) {
-      return 'patch';
+
+  // If we reach here then we know it's non-major
+
+  const fromMinor = versioning.getMinor(currentVersion);
+  const toMinor = versioning.getMinor(newVersion);
+
+  // istanbul ignore if: error case
+  if (fromMinor === null || toMinor === null) {
+    return 'non-major';
+  }
+
+  // Check the minor update type first
+  if (fromMinor !== toMinor) {
+    /* future option
+    if (separateMultipleMinor) {
+      return `v${toMajor}.${toMinor}`;
     }
-    return 'minor';
+    */
+
+    if (separateMinorPatch) {
+      return 'minor';
+    }
+    // default path for minor updates is not to separate them from patch
+    return 'non-major';
+  }
+
+  // If we reach here then we know it's a patch release
+
+  /* future option
+  if (separateMultiplePatch) {
+    const toPatch = versioning.getPatch(newVersion);
+    if (toPatch !== null && separateMultiplePatch) {
+      return `v${toMajor}.${toMinor}.${toPatch}`;
+    }
+  }
+  */
+
+  if (separateMinorPatch) {
+    return 'patch';
   }
+  // default path for patch updates is not to separate them from minor
   return 'non-major';
 }
-- 
GitLab