From e879bf6f30f9c1f610dc24fa5bc8710d282a8ca6 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 16 Nov 2018 11:47:44 +0100
Subject: [PATCH] fix(config): migrate file config

---
 lib/config/file.js                          |  9 +++++++++
 test/_fixtures/config/file.js               | 18 +-----------------
 test/_fixtures/config/file2.js              |  3 +++
 test/config/__snapshots__/file.spec.js.snap |  7 +++++++
 test/config/file.spec.js                    | 19 +++++++++++++++----
 5 files changed, 35 insertions(+), 21 deletions(-)
 create mode 100644 test/_fixtures/config/file2.js
 create mode 100644 test/config/__snapshots__/file.spec.js.snap

diff --git a/lib/config/file.js b/lib/config/file.js
index 00040488c5..bf542b8df0 100644
--- a/lib/config/file.js
+++ b/lib/config/file.js
@@ -1,4 +1,5 @@
 const path = require('path');
+const { migrateConfig } = require('./migration');
 
 module.exports = {
   getConfig,
@@ -17,5 +18,13 @@ function getConfig(env) {
     // Do nothing
     logger.debug('No config file found on disk - skipping');
   }
+  const { isMigrated, migratedConfig } = migrateConfig(config);
+  if (isMigrated) {
+    logger.warn(
+      { originalConfig: config, migratedConfig },
+      'Renovate bot config needs migrating'
+    );
+    config = migratedConfig;
+  }
   return config;
 }
diff --git a/test/_fixtures/config/file.js b/test/_fixtures/config/file.js
index e2ec5f0f64..c0d636dd55 100644
--- a/test/_fixtures/config/file.js
+++ b/test/_fixtures/config/file.js
@@ -1,20 +1,4 @@
 module.exports = {
   token: 'abcdefg',
-  logLevel: 'error',
-  repositories: [
-    'singapore/lint-condo',
-    {
-      repository: 'renovatebot/renovate',
-      packageFiles: ['package2.json'],
-    },
-    {
-      repository: 'renovatebot/renovate',
-      packageFiles: [
-        {
-          packageFile: 'package.json',
-          labels: ['a'],
-        },
-      ],
-    },
-  ],
+  logLevel: 'error'
 };
diff --git a/test/_fixtures/config/file2.js b/test/_fixtures/config/file2.js
new file mode 100644
index 0000000000..b8b35e670d
--- /dev/null
+++ b/test/_fixtures/config/file2.js
@@ -0,0 +1,3 @@
+module.exports = {
+  upgradeInRange: true
+};
diff --git a/test/config/__snapshots__/file.spec.js.snap b/test/config/__snapshots__/file.spec.js.snap
new file mode 100644
index 0000000000..2050852983
--- /dev/null
+++ b/test/config/__snapshots__/file.spec.js.snap
@@ -0,0 +1,7 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`config/file .getConfig() migrates 1`] = `
+Object {
+  "rangeStrategy": "bump",
+}
+`;
diff --git a/test/config/file.spec.js b/test/config/file.spec.js
index 0573dda9ca..5b55c93e9c 100644
--- a/test/config/file.spec.js
+++ b/test/config/file.spec.js
@@ -5,13 +5,24 @@ const customConfig = require('../_fixtures/config/file');
 describe('config/file', () => {
   describe('.getConfig()', () => {
     it('returns empty env', () => {
-      file.getConfig({}).should.eql({});
+      expect(file.getConfig({ RENOVATE_CONFIG_FILE: 'dummylocation' })).toEqual(
+        {}
+      );
     });
     it('parses custom config file', () => {
       const configFile = path.resolve(__dirname, '../_fixtures/config/file.js');
-      file
-        .getConfig({ RENOVATE_CONFIG_FILE: configFile })
-        .should.eql(customConfig);
+      expect(file.getConfig({ RENOVATE_CONFIG_FILE: configFile })).toEqual(
+        customConfig
+      );
+    });
+    it('migrates', () => {
+      const configFile = path.resolve(
+        __dirname,
+        '../_fixtures/config/file2.js'
+      );
+      const res = file.getConfig({ RENOVATE_CONFIG_FILE: configFile });
+      expect(res).toMatchSnapshot();
+      expect(res.rangeStrategy).toEqual('bump');
     });
   });
 });
-- 
GitLab