diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index 2a1e431b394f309fb92d760861c10a0fb6abbe7e..e8b19bdcda42f3bf69daff976ef01a257393bedd 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -216,7 +216,20 @@ describe('workers/branch', () => { }); git.branchExists.mockResolvedValue(false); expect(await branchWorker.processBranch(config, true)).toEqual( - 'pr-hourly-limit-reached' + 'pr-limit-reached' + ); + }); + it('returns if commit limit exceeded', async () => { + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ + ...updatedPackageFiles, + }); + npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ + artifactErrors: [], + updatedArtifacts: [], + }); + git.branchExists.mockResolvedValue(false); + expect(await branchWorker.processBranch(config, false, true)).toEqual( + 'commit-limit-reached' ); }); it('returns if no work', async () => { diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 44c884be16f7c0ac9e22e7d88b62e1cc1b48060a..6c9df3ff13392f08e2ce76465c0f28a006132ee7 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -56,7 +56,8 @@ const rebasingRegex = /\*\*Rebasing\*\*: .*/; export async function processBranch( branchConfig: BranchConfig, - prHourlyLimitReached?: boolean + prLimitReached?: boolean, + commitLimitReached?: boolean ): Promise<ProcessBranchResult> { const config: BranchConfig = { ...branchConfig }; const dependencies = config.upgrades @@ -148,14 +149,20 @@ export async function processBranch( } if ( !branchExists && - prHourlyLimitReached && + prLimitReached && !dependencyDashboardCheck && !config.vulnerabilityAlert ) { - logger.debug( - 'Reached PR creation limit or per run commits limit - skipping branch creation' - ); - return 'pr-hourly-limit-reached'; + logger.debug('Reached PR limit - skipping branch creation'); + return 'pr-limit-reached'; + } + if ( + commitLimitReached && + !dependencyDashboardCheck && + !config.vulnerabilityAlert + ) { + logger.debug('Reached commits limit - skipping branch'); + return 'commit-limit-reached'; } if (branchExists) { logger.debug('Checking if PR has been edited'); diff --git a/lib/workers/common.ts b/lib/workers/common.ts index 5082cb40eb8c1e89af8e81326826aad8dce97f4d..7ba92997535b56f789f5ed33ef686f302ba5d9b6 100644 --- a/lib/workers/common.ts +++ b/lib/workers/common.ts @@ -86,7 +86,8 @@ export type ProcessBranchResult = | 'pending' | 'pr-created' | 'pr-edited' - | 'pr-hourly-limit-reached' + | 'pr-limit-reached' + | 'commit-limit-reached' | 'rebase'; export interface BranchConfig diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index 2717c76ae92044bde0cd7d03249a8bdf928943f0..47b80760267d6ac4527055ad876edd53d79f95e5 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -169,14 +169,14 @@ describe('workers/repository/master-issue', () => { ...mock<BranchConfig>(), prTitle: 'pr5', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep5' }], - res: 'pr-hourly-limit-reached', + res: 'pr-limit-reached', branchName: 'branchName5', }, { ...mock<BranchConfig>(), prTitle: 'pr6', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep6' }], - res: 'pr-hourly-limit-reached', + res: 'pr-limit-reached', branchName: 'branchName6', }, { diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index c80d7289728048e0cfe4b087de3f976a3e930ba0..69d62579bc03f405aaf16d1ecb9cf55cbc147454 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -96,7 +96,8 @@ export async function ensureMasterIssue( issueBody += '\n'; } const rateLimited = branches.filter( - (branch) => branch.res && branch.res.endsWith('pr-hourly-limit-reached') + (branch) => + branch.res === 'pr-limit-reached' || branch.res === 'commit-limit-reached' ); if (rateLimited.length) { issueBody += '## Rate Limited\n\n'; @@ -155,7 +156,8 @@ export async function ensureMasterIssue( 'needs-approval', 'needs-pr-approval', 'not-scheduled', - 'pr-hourly-limit-reached', + 'pr-limit-reached', + 'commit-limit-reached', 'already-existed', 'error', 'automerged', diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts index 432b3b6cab47769355d6741b2b3d19514b4dae1d..1ef19d351c5d32599d5c78b85f5933475b933ab7 100644 --- a/lib/workers/repository/process/write.ts +++ b/lib/workers/repository/process/write.ts @@ -31,10 +31,9 @@ export async function writeUpdates( logger.debug({ prsRemaining }, 'Calculated maximum PRs remaining this run'); for (const branch of branches) { addMeta({ branch: branch.branchName }); - const res = await processBranch( - branch, - prsRemaining <= 0 || getLimitRemaining('prCommitsPerRunLimit') <= 0 - ); + const prLimitReached = prsRemaining <= 0; + const commitLimitReached = getLimitRemaining('prCommitsPerRunLimit') <= 0; + const res = await processBranch(branch, prLimitReached, commitLimitReached); branch.res = res; if (res === 'automerged' && branch.automergeType !== 'pr-comment') { // Stop procesing other branches because base branch has been changed