diff --git a/lib/workers/global/limits.spec.ts b/lib/workers/global/limits.spec.ts index 9e48e5b716a78c..f6460e316ec399 100644 --- a/lib/workers/global/limits.spec.ts +++ b/lib/workers/global/limits.spec.ts @@ -5,7 +5,6 @@ import { hasMultipleLimits, incCountValue, incLimitedValue, - isCountReached, isLimitReached, resetAllLimits, setCount, @@ -217,7 +216,7 @@ describe('workers/global/limits', () => { }); }); - describe('isCountReached', () => { + describe('isLimitReached', () => { it('returns false based on concurrent limits', () => { setCount('PullRequests', 1); setCount('HourlyPullRequests', 1); @@ -240,10 +239,10 @@ describe('workers/global/limits', () => { }, ]); expect( - isCountReached('Branches', partial({ upgrades })), + isLimitReached('Branches', partial({ upgrades })), ).toBe(false); expect( - isCountReached('PullRequests', partial({ upgrades })), + isLimitReached('PullRequests', partial({ upgrades })), ).toBe(false); }); @@ -269,10 +268,10 @@ describe('workers/global/limits', () => { }, ]); expect( - isCountReached('Branches', partial({ upgrades })), + isLimitReached('Branches', partial({ upgrades })), ).toBe(true); expect( - isCountReached('PullRequests', partial({ upgrades })), + isLimitReached('PullRequests', partial({ upgrades })), ).toBe(true); }); @@ -298,10 +297,10 @@ describe('workers/global/limits', () => { }, ]); expect( - isCountReached('Branches', partial({ upgrades })), + isLimitReached('Branches', partial({ upgrades })), ).toBe(true); expect( - isCountReached('PullRequests', partial({ upgrades })), + isLimitReached('PullRequests', partial({ upgrades })), ).toBe(true); }); }); diff --git a/lib/workers/global/limits.ts b/lib/workers/global/limits.ts index 431d6b0b1633c4..29f21077876fc9 100644 --- a/lib/workers/global/limits.ts +++ b/lib/workers/global/limits.ts @@ -28,7 +28,7 @@ export function incLimitedValue(key: Limit, incBy = 1): void { }); } -export function isLimitReached(key: Limit): boolean { +export function handleCommitsLimit(key: Limit): boolean { const limit = limits.get(key); // TODO: fix me? // eslint-disable-next-line @typescript-eslint/prefer-optional-chain @@ -64,7 +64,7 @@ export function incCountValue(key: CountName, incBy = 1): void { }); } -export function isCountReached( +export function handleOtherLimits( key: Exclude, config: BranchConfig, ): boolean { @@ -176,3 +176,14 @@ export function hasMultipleLimits( return distinctLimits.size > 1; } + +export function isLimitReached( + limit: 'Branches' | 'PullRequests' | 'Commits', + config?: BranchConfig, +): boolean { + if (limit === 'Commits') { + return handleCommitsLimit(limit); + } + + return handleOtherLimits(limit, config!); +} diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 0d8f46d23d4866..ba8aba7d85a76f 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -540,7 +540,7 @@ describe('workers/repository/update/branch/index', () => { artifactErrors: [], updatedArtifacts: [], }); - limits.isCountReached.mockReturnValueOnce(true); + limits.isLimitReached.mockReturnValueOnce(true); limits.isLimitReached.mockReturnValueOnce(false); expect(await branchWorker.processBranch(config)).toEqual({ branchExists: false, @@ -598,7 +598,7 @@ describe('workers/repository/update/branch/index', () => { type: 'without-pr', prBlockedBy: 'RateLimited', }); - limits.isCountReached.mockReturnValue(false); + limits.isLimitReached.mockReturnValue(false); //git.getBranchCommit.mockReturnValue('123test');TODO:not needed? expect(await branchWorker.processBranch(config)).toEqual({ branchExists: true, @@ -617,7 +617,7 @@ describe('workers/repository/update/branch/index', () => { updatedArtifacts: [], }); scm.branchExists.mockResolvedValue(false); - limits.isCountReached.mockReturnValueOnce(false); + limits.isLimitReached.mockReturnValueOnce(false); limits.isLimitReached.mockReturnValueOnce(true); expect(await branchWorker.processBranch(config)).toEqual({ branchExists: false, diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 6a5353b89c8f15..b9340b6036b53e 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -34,7 +34,7 @@ import { import { coerceNumber } from '../../../../util/number'; import { toMs } from '../../../../util/pretty-time'; import * as template from '../../../../util/template'; -import { counts, isCountReached, isLimitReached } from '../../../global/limits'; +import { counts, isLimitReached } from '../../../global/limits'; import type { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; import { embedChangelogs } from '../../changelog'; import { ensurePr, getPlatformPrOptions } from '../pr'; @@ -216,7 +216,7 @@ export async function processBranch( if ( !branchExists && - isCountReached('Branches', branchConfig) && + isLimitReached('Branches', branchConfig) && !dependencyDashboardCheck && !config.isVulnerabilityAlert ) { diff --git a/lib/workers/repository/update/pr/index.spec.ts b/lib/workers/repository/update/pr/index.spec.ts index 8e773260ece2c4..3a8716e6a43050 100644 --- a/lib/workers/repository/update/pr/index.spec.ts +++ b/lib/workers/repository/update/pr/index.spec.ts @@ -101,7 +101,7 @@ describe('workers/repository/update/pr/index', () => { it('aborts PR creation once limit is exceeded', async () => { platform.createPr.mockResolvedValueOnce(pr); - limits.isCountReached.mockReturnValueOnce(true); + limits.isLimitReached.mockReturnValueOnce(true); config.fetchChangeLogs = 'pr'; @@ -114,7 +114,7 @@ describe('workers/repository/update/pr/index', () => { it('ignores PR limits on vulnerability alert', async () => { platform.createPr.mockResolvedValueOnce(pr); - limits.isCountReached.mockReturnValueOnce(true); + limits.isLimitReached.mockReturnValueOnce(true); const prConfig = { ...config, isVulnerabilityAlert: true }; delete prConfig.prTitle; // for coverage diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index 5c9cdad4d3230e..d6d3981353157f 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -27,7 +27,7 @@ import { stripEmojis } from '../../../../util/emoji'; import { fingerprint } from '../../../../util/fingerprint'; import { getBranchLastCommitTime } from '../../../../util/git'; import { memoize } from '../../../../util/memoize'; -import { incCountValue, isCountReached } from '../../../global/limits'; +import { incCountValue, isLimitReached } from '../../../global/limits'; import type { BranchConfig, BranchUpgradeConfig, @@ -482,7 +482,7 @@ export async function ensurePr( try { if ( !dependencyDashboardCheck && - isCountReached('PullRequests', prConfig) && + isLimitReached('PullRequests', prConfig) && !config.isVulnerabilityAlert ) { logger.debug('Skipping PR - limit reached');