From ad4b9feb929e270c6b59fcb5786a936c33326adf Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 30 Jan 2018 11:38:55 +0100 Subject: [PATCH] feat: prConcurrentLimit Adds a new feature to limit the number of concurrent branches/PRs to have open at any one time. Defaults to 0 (disabled), set it to a positive integer to enforce that limit. --- lib/config/definitions.js | 7 +++++++ lib/workers/repository/write.js | 16 +++++++++++++++- test/workers/repository/write.spec.js | 10 ++++++++++ .../_posts/2017-10-05-configuration-options.md | 11 +++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 77c12385f8..e0c0d49d9a 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -561,6 +561,13 @@ const options = [ type: 'integer', default: 0, // no limit }, + { + name: 'prConcurrentLimit', + description: + 'Limit to a maximum of x concurrent branches/PRs. 0 (default) means no limit.', + type: 'integer', + default: 0, // no limit + }, // Automatic merging { name: 'automerge', diff --git a/lib/workers/repository/write.js b/lib/workers/repository/write.js index 2f30fec5bd..109c7272a8 100644 --- a/lib/workers/repository/write.js +++ b/lib/workers/repository/write.js @@ -29,11 +29,25 @@ async function writeUpdates(config) { pr.branchName !== 'renovate/configure' && moment(pr.createdAt).isAfter(currentHourStart) ).length; - logger.info(`PR creations remaining this hour: ${prsRemaining}`); + logger.info(`PR hourly limit remaining: ${prsRemaining}`); } catch (err) { logger.error('Error checking PRs created per hour'); } } + if (config.prConcurrentLimit) { + logger.debug(`Enforcing prConcurrentLimit (${config.prConcurrentLimit})`); + let currentlyOpen = 0; + for (const branch of branches) { + if (await platform.branchExists(branch.branchName)) { + currentlyOpen += 1; + } + } + logger.debug(`${currentlyOpen} PRs are currently open`); + const concurrentRemaining = config.prConcurrentLimit - currentlyOpen; + logger.info(`PR concurrent limit remaining: ${concurrentRemaining}`); + prsRemaining = + prsRemaining < concurrentRemaining ? prsRemaining : concurrentRemaining; + } try { for (const branch of branches) { const res = await branchWorker.processBranch({ diff --git a/test/workers/repository/write.spec.js b/test/workers/repository/write.spec.js index 89435d9d12..f695164caa 100644 --- a/test/workers/repository/write.spec.js +++ b/test/workers/repository/write.spec.js @@ -21,6 +21,16 @@ describe('workers/repository/write', () => { const res = await writeUpdates(config); expect(res).toEqual('done'); }); + it('calculates concurrent limit remaining', async () => { + config.branches = ['renovate/chalk-2.x']; + config.prConcurrentLimit = 1; + platform.getPrList.mockReturnValueOnce([ + { created_at: moment().format() }, + ]); + platform.branchExists.mockReturnValueOnce(true); + const res = await writeUpdates(config); + expect(res).toEqual('done'); + }); it('handles error in calculation', async () => { config.branches = []; config.prHourlyLimit = 1; diff --git a/website/docs/_posts/2017-10-05-configuration-options.md b/website/docs/_posts/2017-10-05-configuration-options.md index d834cfb375..c91ef44202 100644 --- a/website/docs/_posts/2017-10-05-configuration-options.md +++ b/website/docs/_posts/2017-10-05-configuration-options.md @@ -713,6 +713,17 @@ Pull Request body template. Although the PR body can be customised by you, it might be quite challenging. If you think the Pull Request should include different information or could be formatted better, perhaps try raising an [Issue](https://github.com/renovateapp/renovate/issues) and let us solve it for you and for everyone else too. +## prConcurrentLimit + +Limit to a maximum of x concurrent branches/PRs. 0 (default) means no limit. + +| name | value | +| ------- | ------- | +| type | integer | +| default | 0 | + +This setting - if enabled - limits Renovate to a maximum of x concurrent PRs open at any time. + ## prCreation When to create the PR for a branch. -- GitLab