diff --git a/lib/workers/repository/process/limits.spec.ts b/lib/workers/repository/process/limits.spec.ts index 01f49ce673f9bec2592fe41b05c8cc8883bf4d7f..fe6f7c982db9503460bc8b0e51e6558cfb8b9b75 100644 --- a/lib/workers/repository/process/limits.spec.ts +++ b/lib/workers/repository/process/limits.spec.ts @@ -127,13 +127,30 @@ describe(getName(), () => { }); describe('getBranchesRemaining()', () => { - it('returns concurrent branches', () => { - config.branchConcurrentLimit = 20; - git.branchExists.mockReturnValueOnce(true); - const res = limits.getBranchesRemaining(config, [ - { branchName: 'foo' }, - ] as never); - expect(res).toEqual(19); + it('returns minimal of both limits', async () => { + platform.getPrList.mockResolvedValue([]); + + await expect( + limits.getBranchesRemaining( + { + ...config, + prHourlyLimit: 3, + branchConcurrentLimit: 5, + }, + [] + ) + ).resolves.toEqual(3); + + await expect( + limits.getBranchesRemaining( + { + ...config, + prHourlyLimit: 11, + branchConcurrentLimit: 7, + }, + [] + ) + ).resolves.toEqual(7); }); }); }); diff --git a/lib/workers/repository/process/limits.ts b/lib/workers/repository/process/limits.ts index 68694e13b89ef646212d4849e3b0a5260e72635e..e0a5ef9885c7842d05bbca3c6ed4a36dace94e15 100644 --- a/lib/workers/repository/process/limits.ts +++ b/lib/workers/repository/process/limits.ts @@ -122,9 +122,11 @@ export function getConcurrentBranchesRemaining( return 99; } -export function getBranchesRemaining( +export async function getBranchesRemaining( config: RenovateConfig, branches: BranchConfig[] -): number { - return getConcurrentBranchesRemaining(config, branches); +): Promise<number> { + const hourlyRemaining = await getPrHourlyRemaining(config); + const concurrentRemaining = getConcurrentBranchesRemaining(config, branches); + return Math.min(hourlyRemaining, concurrentRemaining); } diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts index a0f3f064162bf6a04869bbdfd33d8ec0692907f9..1e40134c729de9e95c3471da18ad2188a008a34f 100644 --- a/lib/workers/repository/process/write.spec.ts +++ b/lib/workers/repository/process/write.spec.ts @@ -19,7 +19,7 @@ const limits = mocked(_limits); branchWorker.processBranch = jest.fn(); limits.getPrsRemaining = jest.fn().mockResolvedValue(99); -limits.getBranchesRemaining = jest.fn().mockReturnValue(99); +limits.getBranchesRemaining = jest.fn().mockResolvedValue(99); let config: RenovateConfig; beforeEach(() => { @@ -66,7 +66,7 @@ describe(getName(), () => { }); git.branchExists.mockReturnValueOnce(false); git.branchExists.mockReturnValueOnce(true); - limits.getBranchesRemaining.mockReturnValueOnce(1); + limits.getBranchesRemaining.mockResolvedValueOnce(1); expect(isLimitReached(Limit.Branches)).toBeFalse(); await writeUpdates({ config }, branches); expect(isLimitReached(Limit.Branches)).toBeTrue(); diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts index ca087fda93a1752c754c5e65267032146b11552d..1fa41c3c698bbe28804c8a3fa07225efd558ba15 100644 --- a/lib/workers/repository/process/write.ts +++ b/lib/workers/repository/process/write.ts @@ -25,7 +25,7 @@ export async function writeUpdates( logger.debug({ prsRemaining }, 'Calculated maximum PRs remaining this run'); setMaxLimit(Limit.PullRequests, prsRemaining); - const branchesRemaining = getBranchesRemaining(config, branches); + const branchesRemaining = await getBranchesRemaining(config, branches); logger.debug( { branchesRemaining }, 'Calculated maximum branches remaining this run'