From c28176e8795a7de0c8af7f8cec79ace80086059b Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Thu, 17 Aug 2017 12:33:21 +0200
Subject: [PATCH] refactor: use logger const in repository worker (#685)

---
 lib/workers/repository/index.js | 35 +++++++++++++++++----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js
index 160a3d8d29..a7cf0732d7 100644
--- a/lib/workers/repository/index.js
+++ b/lib/workers/repository/index.js
@@ -12,19 +12,20 @@ module.exports = {
 
 async function renovateRepository(repoConfig, token) {
   let config = { ...repoConfig };
+  const { logger } = config;
   config.errors = [];
   config.warnings = [];
-  config.logger.trace({ config }, 'renovateRepository');
+  logger.trace({ config }, 'renovateRepository');
   try {
     config = await apis.initApis(config, token);
     config = await apis.mergeRenovateJson(config);
     if (config.enabled === false) {
-      config.logger.debug('repository is disabled');
+      logger.debug('repository is disabled');
       await cleanup.pruneStaleBranches(config, []);
       return;
     }
     if (config.isFork && !config.renovateJsonPresent) {
-      config.logger.debug('repository is a fork and not manually configured');
+      logger.debug('repository is a fork and not manually configured');
       return;
     }
     if (config.baseBranch) {
@@ -38,25 +39,25 @@ async function renovateRepository(repoConfig, token) {
           depName: 'baseBranch',
           message,
         });
-        config.logger.warn(message);
+        logger.warn(message);
       }
     }
     // Detect package files in default branch if not manually provisioned
     if (config.packageFiles.length === 0) {
-      config.logger.debug('Detecting package files');
+      logger.debug('Detecting package files');
       config = await apis.detectPackageFiles(config);
       // If we can't detect any package.json then return
       if (config.packageFiles.length === 0) {
-        config.logger.info('Cannot detect package.json');
+        logger.info('Cannot detect package.json');
         return;
       }
-      config.logger.debug(
+      logger.debug(
         `Detected ${config.packageFiles
           .length} package files: ${config.packageFiles}`
       );
     }
     config = await apis.resolvePackageFiles(config);
-    config.logger.trace({ config }, 'post-packageFiles config');
+    logger.trace({ config }, 'post-packageFiles config');
     config.repoIsOnboarded = await onboarding.getOnboardingStatus(config);
     if (!config.repoIsOnboarded) {
       config.contentBaseBranch = `${config.branchPrefix}configure`;
@@ -79,19 +80,19 @@ async function renovateRepository(repoConfig, token) {
             depName: 'baseBranch',
             message,
           });
-          config.logger.warn(message);
+          logger.warn(message);
         }
       }
       config = await apis.resolvePackageFiles(config);
-      config.logger.trace({ config }, 'onboarding config');
+      logger.trace({ config }, 'onboarding config');
     }
     const allUpgrades = await upgrades.determineRepoUpgrades(config);
     const res = await upgrades.branchifyUpgrades(allUpgrades, config.logger);
     config.errors = config.errors.concat(res.errors);
     config.warnings = config.warnings.concat(res.warnings);
     const branchUpgrades = res.upgrades;
-    config.logger.debug(`Updating ${branchUpgrades.length} branch(es)`);
-    config.logger.trace({ config: branchUpgrades }, 'branchUpgrades');
+    logger.debug(`Updating ${branchUpgrades.length} branch(es)`);
+    logger.trace({ config: branchUpgrades }, 'branchUpgrades');
     let branchList;
     if (config.repoIsOnboarded) {
       for (const branchUpgrade of branchUpgrades) {
@@ -102,20 +103,20 @@ async function renovateRepository(repoConfig, token) {
         );
       }
       branchList = branchUpgrades.map(upgrade => upgrade.branchName);
-      config.logger.debug(`branchList=${branchList}`);
+      logger.debug(`branchList=${branchList}`);
     } else {
       await onboarding.ensurePr(config, branchUpgrades);
-      config.logger.info('"Configure Renovate" PR needs to be closed first');
+      logger.info('"Configure Renovate" PR needs to be closed first');
       branchList = [`${config.branchPrefix}configure`];
     }
     await cleanup.pruneStaleBranches(config, branchList);
   } catch (err) {
     // Swallow this error so that other repositories can be processed
     if (err.message === 'uninitiated') {
-      repoConfig.logger.info('Repository is unitiated - skipping');
+      logger.info('Repository is unitiated - skipping');
     } else {
-      repoConfig.logger.error(`Failed to process repository: ${err.message}`);
-      repoConfig.logger.debug({ err });
+      logger.error(`Failed to process repository: ${err.message}`);
+      logger.debug({ err });
     }
   }
 }
-- 
GitLab