From 2364efdb3905e6ce823ed777eae838546fe2a104 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 20 Mar 2018 06:48:27 +0100
Subject: [PATCH] fix: improve lockfile maintenance deletion logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Set lock file branches to always rebase stale, and delete if there’s no work to do.
---
 lib/config/definitions.js                    | 1 +
 lib/workers/branch/index.js                  | 8 ++++++--
 test/config/__snapshots__/index.spec.js.snap | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/config/definitions.js b/lib/config/definitions.js
index ddf102736f..b568b101a2 100644
--- a/lib/config/definitions.js
+++ b/lib/config/definitions.js
@@ -697,6 +697,7 @@ const options = [
     default: {
       enabled: false,
       recreateClosed: true,
+      rebaseStalePrs: true,
       branchName: template('branchName', 'lock-file-maintenance'),
       commitMessage: template('commitMessage', 'lock-file-maintenance'),
       prTitle: template('prTitle', 'lock-file-maintenance'),
diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js
index 2a6d29bc36..4a7bfd3e85 100644
--- a/lib/workers/branch/index.js
+++ b/lib/workers/branch/index.js
@@ -141,8 +141,12 @@ async function processBranch(branchConfig) {
     }
 
     const committedFiles = await commitFilesToBranch(config);
-    if (config.type === 'lockFileMaintenance' && !config.committedFiles) {
-      logger.debug(
+    if (
+      config.type === 'lockFileMaintenance' &&
+      !committedFiles &&
+      !config.parentBranch
+    ) {
+      logger.warn(
         'Deleting lock file maintenance branch as master lock file no longer needs updating'
       );
       return 'delete';
diff --git a/test/config/__snapshots__/index.spec.js.snap b/test/config/__snapshots__/index.spec.js.snap
index 4985f2587c..9e6bbef655 100644
--- a/test/config/__snapshots__/index.spec.js.snap
+++ b/test/config/__snapshots__/index.spec.js.snap
@@ -38,6 +38,7 @@ Please make sure the following warnings are safe to ignore:
 {{/each}}
 {{/if}}",
   "prTitle": "Lock file maintenance",
+  "rebaseStalePrs": true,
   "recreateClosed": true,
   "schedule": Array [
     "on monday",
-- 
GitLab