From 93b13b55db544651963dd80f4b97dc7fc1bb96cf Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Sun, 9 Jul 2017 05:35:41 +0200
Subject: [PATCH] feat(onboarding): Allow branch cleanup after onboarding
 (#477)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refactored location of branch cleanup so that it can be run even if onboarding is enabled.
This means someone can “undo” a closed Configure Renovate and all other PRs would get cleaned up.
---
 lib/workers/repository/index.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js
index 983a634d07..084ccdd5b9 100644
--- a/lib/workers/repository/index.js
+++ b/lib/workers/repository/index.js
@@ -77,6 +77,7 @@ async function renovateRepository(packageFileConfig) {
     const branchUpgrades = res.upgrades;
     config.logger.debug(`Updating ${branchUpgrades.length} branch(es)`);
     config.logger.trace({ config: branchUpgrades }, 'branchUpgrades');
+    let branchList;
     if (config.repoIsOnboarded) {
       for (const branchUpgrade of branchUpgrades) {
         await branchWorker.processBranchUpgrades(
@@ -85,13 +86,15 @@ async function renovateRepository(packageFileConfig) {
           config.warnings
         );
       }
-      const branchList = branchUpgrades.map(upgrade => upgrade.branchName);
+      branchList = branchUpgrades.map(upgrade => upgrade.branchName);
       config.logger.debug(`branchList=${branchList}`);
       await cleanup.pruneStaleBranches(config, branchList);
     } else {
       await onboarding.ensurePr(config, branchUpgrades);
       config.logger.info('"Configure Renovate" PR needs to be closed first');
+      branchList = ['renovate/configure'];
     }
+    await cleanup.pruneStaleBranches(config, branchList);
   } catch (error) {
     // Swallow this error so that other repositories can be processed
     config.logger.error(`Failed to process repository: ${error.message}`);
-- 
GitLab