From 9766a94fbfa5cf96d38264365821d11cd6faef1f Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sun, 11 Feb 2018 19:58:59 +0100 Subject: [PATCH] fix: check for truthy arrays before checking length --- lib/workers/branch/check-existing.js | 5 ++++- lib/workers/branch/commit.js | 2 +- lib/workers/branch/index.js | 8 +++++--- lib/workers/branch/lock-files.js | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/workers/branch/check-existing.js b/lib/workers/branch/check-existing.js index 9701e08878..0b788635df 100644 --- a/lib/workers/branch/check-existing.js +++ b/lib/workers/branch/check-existing.js @@ -12,7 +12,10 @@ async function prAlreadyExisted(config) { // Return if same PR already existed // Check for current PR title format // See #1205 for why we check for !open or closed - const statusValue = config.packageFiles.length === 1 ? '!open' : 'closed'; + const statusValue = + config.packageFiles && config.packageFiles.length === 1 + ? '!open' + : 'closed'; let pr = await platform.findPr( config.branchName, config.prTitle, diff --git a/lib/workers/branch/commit.js b/lib/workers/branch/commit.js index b3b8ff1ed6..135b5b6ba1 100644 --- a/lib/workers/branch/commit.js +++ b/lib/workers/branch/commit.js @@ -8,7 +8,7 @@ async function commitFilesToBranch(config) { const updatedFiles = config.updatedPackageFiles.concat( config.updatedLockFiles ); - if (updatedFiles.length) { + if (updatedFiles && updatedFiles.length) { logger.debug(`${updatedFiles.length} file(s) to commit`); let commitMessage = handlebars.compile(config.commitMessage)(config); if (config.semanticCommits) { diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js index 00476b7de2..f32a4a597a 100644 --- a/lib/workers/branch/index.js +++ b/lib/workers/branch/index.js @@ -35,7 +35,9 @@ async function processBranch(branchConfig) { return 'pr-hourly-limit-reached'; } try { - logger.info(`Branch has ${dependencies.length} upgrade(s)`); + logger.info( + `Branch has ${dependencies ? dependencies.length : 0} upgrade(s)` + ); // Check if branch already existed let pr = await prAlreadyExisted(config); @@ -118,7 +120,7 @@ async function processBranch(branchConfig) { Object.assign(config, await getParentBranch(config)); logger.debug(`Using parentBranch: ${config.parentBranch}`); Object.assign(config, await getUpdatedPackageFiles(config)); - if (config.updatedPackageFiles.length) { + if (config.updatedPackageFiles && config.updatedPackageFiles.length) { logger.debug( { updatedPackageFiles: config.updatedPackageFiles }, `Updated ${config.updatedPackageFiles.length} package files` @@ -127,7 +129,7 @@ async function processBranch(branchConfig) { logger.debug('No package files need updating'); } Object.assign(config, await getUpdatedLockFiles(config)); - if (config.updatedLockFiles.length) { + if (config.updatedLockFiles && config.updatedLockFiles.length) { logger.debug( { updatedLockFiles: config.updatedLockFiles.map(f => f.name) }, `Updated ${config.updatedLockFiles.length} lock files` diff --git a/lib/workers/branch/lock-files.js b/lib/workers/branch/lock-files.js index a11db9a8b4..385aeee1b5 100644 --- a/lib/workers/branch/lock-files.js +++ b/lib/workers/branch/lock-files.js @@ -435,7 +435,7 @@ async function getUpdatedLockFiles(config) { } } - if (dirs.lernaDirs.length) { + if (dirs.lernaDirs && dirs.lernaDirs.length) { let manager; let lockFile; if (config.lernaLockFile === 'npm') { -- GitLab