From 3099bf9da131061f672cde7b41441faa684f1fce Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Tue, 15 Aug 2017 11:54:36 +0200
Subject: [PATCH] fix: migrate last day of month schedule to first of month
 (#680)

---
 lib/config/migration.js                          | 10 ++++++++++
 lib/workers/branch/schedule.js                   |  6 +++++-
 test/config/__snapshots__/migration.spec.js.snap |  4 +++-
 test/config/migration.spec.js                    |  2 +-
 test/workers/branch/schedule.spec.js             |  5 +++++
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/config/migration.js b/lib/config/migration.js
index 894f5dff2c..b65c8500a6 100644
--- a/lib/config/migration.js
+++ b/lib/config/migration.js
@@ -54,6 +54,16 @@ function migrateConfig(config, parentConfig) {
       isMigrated = true;
       migratedConfig.packagePatterns = [val];
       delete migratedConfig.packagePattern;
+    } else if (key === 'schedule') {
+      for (let i = 0; i < val.length; i += 1) {
+        if (val[i].indexOf('on the last day of the month') !== -1) {
+          isMigrated = true;
+          migratedConfig.schedule[i] = val[i].replace(
+            'on the last day of the month',
+            'on the first day of the month'
+          );
+        }
+      }
     } else if (
       typeof val === 'string' &&
       val.indexOf('{{semanticPrefix}}') === 0
diff --git a/lib/workers/branch/schedule.js b/lib/workers/branch/schedule.js
index 8ca82a8252..8b93d9b3fd 100644
--- a/lib/workers/branch/schedule.js
+++ b/lib/workers/branch/schedule.js
@@ -32,7 +32,11 @@ function hasValidSchedule(schedule) {
       message = `Schedule "${scheduleText}" should not specify minutes`;
       return true;
     }
-    if (!parsedSchedule.schedules.some(s => s.d || s.t_a || s.t_b)) {
+    if (
+      !parsedSchedule.schedules.some(
+        s => s.d !== undefined || s.D || s.t_a !== undefined || s.t_b
+      )
+    ) {
       message = `Schedule "${scheduleText}" has no days of week or time of day`;
       return true;
     }
diff --git a/test/config/__snapshots__/migration.spec.js.snap b/test/config/__snapshots__/migration.spec.js.snap
index a705f286c3..6a70ff1546 100644
--- a/test/config/__snapshots__/migration.spec.js.snap
+++ b/test/config/__snapshots__/migration.spec.js.snap
@@ -22,7 +22,9 @@ Object {
     },
   ],
   "prTitle": "some pr title",
-  "schedule": "after 5pm",
+  "schedule": Array [
+    "on the first day of the month",
+  ],
   "semanticPrefix": "fix(deps):",
 }
 `;
diff --git a/test/config/migration.spec.js b/test/config/migration.spec.js
index ec0fb6cf9e..6d9307dc37 100644
--- a/test/config/migration.spec.js
+++ b/test/config/migration.spec.js
@@ -10,7 +10,7 @@ describe('config/migration', () => {
         onboarding: 'false',
         automerge: false,
         autodiscover: 'true',
-        schedule: 'after 5pm',
+        schedule: ['on the last day of the month'],
         commitMessage: '{{semanticPrefix}}some commit message',
         prTitle: '{{semanticPrefix}}some pr title',
         semanticPrefix: 'fix(deps): ',
diff --git a/test/workers/branch/schedule.spec.js b/test/workers/branch/schedule.spec.js
index 3d42f32f62..8b09c38b1a 100644
--- a/test/workers/branch/schedule.spec.js
+++ b/test/workers/branch/schedule.spec.js
@@ -41,6 +41,11 @@ describe('workers/branch/schedule', () => {
     it('returns true if schedule has a start time', () => {
       expect(schedule.hasValidSchedule(['after 8:00pm'])[0]).toBe(true);
     });
+    it('returns true for first day of the month', () => {
+      expect(
+        schedule.hasValidSchedule(['on the first day of the month'])[0]
+      ).toBe(true);
+    });
     it('returns true if schedule has an end time', () => {
       expect(schedule.hasValidSchedule(['before 6:00am'])[0]).toBe(true);
     });
-- 
GitLab