From 1f128bbcc24d0b426bc6cc0a6f3143abb4e48507 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Wed, 3 Oct 2018 15:57:01 +0200 Subject: [PATCH] refactor: processBranch function interface --- lib/workers/branch/index.js | 4 ++-- lib/workers/repository/process/write.js | 7 +++---- test/workers/branch/index.spec.js | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js index 81b03cd0f8..fc55bdbc6b 100644 --- a/lib/workers/branch/index.js +++ b/lib/workers/branch/index.js @@ -16,7 +16,7 @@ module.exports = { processBranch, }; -async function processBranch(branchConfig, packageFiles) { +async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) { logger.debug(`processBranch with ${branchConfig.upgrades.length} upgrades`); const config = { ...branchConfig }; const dependencies = config.upgrades @@ -33,7 +33,7 @@ async function processBranch(branchConfig, packageFiles) { await platform.setBaseBranch(config.baseBranch); const branchExists = await platform.branchExists(config.branchName); logger.debug(`branchExists=${branchExists}`); - if (!branchExists && config.prHourlyLimitReached) { + if (!branchExists && prHourlyLimitReached) { logger.info('Reached PR creation limit - skipping branch creation'); return 'pr-hourly-limit-reached'; } diff --git a/lib/workers/repository/process/write.js b/lib/workers/repository/process/write.js index ef08616571..9fa0bc5877 100644 --- a/lib/workers/repository/process/write.js +++ b/lib/workers/repository/process/write.js @@ -25,12 +25,11 @@ async function writeUpdates(config, packageFiles, allBranches) { let prsRemaining = await getPrsRemaining(config, branches); for (const branch of branches) { const res = await branchWorker.processBranch( - { - ...branch, - prHourlyLimitReached: prsRemaining <= 0, - }, + branch, + prsRemaining <= 0, packageFiles ); + branch.res = res; if (res === 'pr-closed' || res === 'automerged') { // Stop procesing other branches because base branch has been changed return res; diff --git a/test/workers/branch/index.spec.js b/test/workers/branch/index.spec.js index fcc461dc4c..147597dabe 100644 --- a/test/workers/branch/index.spec.js +++ b/test/workers/branch/index.spec.js @@ -155,8 +155,7 @@ describe('workers/branch', () => { updatedLockFiles: [], }); platform.branchExists.mockReturnValue(false); - config.prHourlyLimitReached = true; - expect(await branchWorker.processBranch(config)).toEqual( + expect(await branchWorker.processBranch(config, true)).toEqual( 'pr-hourly-limit-reached' ); }); -- GitLab