From 6431cf6861a150bed29d85be2548b4e1de0acbef Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 7 May 2018 07:59:53 +0200
Subject: [PATCH] refactor: move sortBranches

---
 lib/workers/repository/index.js        | 21 ++-------------------
 lib/workers/repository/process/sort.js | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 19 deletions(-)
 create mode 100644 lib/workers/repository/process/sort.js

diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js
index 0c19161c13..6f87d45d01 100644
--- a/lib/workers/repository/index.js
+++ b/lib/workers/repository/index.js
@@ -6,6 +6,7 @@ const { handleError } = require('./error');
 const { finaliseRepo } = require('./finalise');
 const { processResult } = require('./result');
 const { resolvePackageFiles } = require('../../manager');
+const { sortBranches } = require('./process/sort');
 
 module.exports = {
   renovateRepository,
@@ -50,25 +51,7 @@ async function renovateRepository(repoConfig) {
       config = await resolvePackageFiles(config);
       config = await determineUpdates(config);
     }
-
-    // Sort branches
-    const sortOrder = [
-      'pin',
-      'digest',
-      'patch',
-      'minor',
-      'major',
-      'lockFileMaintenance',
-    ];
-    config.branches.sort((a, b) => {
-      const sortDiff = sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type);
-      if (sortDiff !== 0) {
-        // type is different
-        return sortDiff;
-      }
-      // Sort by prTitle
-      return a.prTitle < b.prTitle ? -1 : 1;
-    });
+    sortBranches(config.branches);
     res = config.repoIsOnboarded
       ? await writeUpdates(config)
       : await ensureOnboardingPr(config, config.branches);
diff --git a/lib/workers/repository/process/sort.js b/lib/workers/repository/process/sort.js
new file mode 100644
index 0000000000..6186d39044
--- /dev/null
+++ b/lib/workers/repository/process/sort.js
@@ -0,0 +1,22 @@
+module.exports = { sortBranches };
+
+function sortBranches(branches) {
+  // Sort branches
+  const sortOrder = [
+    'pin',
+    'digest',
+    'patch',
+    'minor',
+    'major',
+    'lockFileMaintenance',
+  ];
+  logger.debug({ branches }, 'branches');
+  branches.sort((a, b) => {
+    const sortDiff = sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type);
+    if (sortDiff !== 0) {
+      return sortDiff;
+    }
+    // Sort by prTitle if type is the same
+    return a.prTitle < b.prTitle ? -1 : 1;
+  });
+}
-- 
GitLab