diff --git a/lib/workers/repository/updates/generate.spec.ts b/lib/workers/repository/updates/generate.spec.ts index 3332212e322ae0..6769da86bb6803 100644 --- a/lib/workers/repository/updates/generate.spec.ts +++ b/lib/workers/repository/updates/generate.spec.ts @@ -703,6 +703,54 @@ describe('workers/repository/updates/generate', () => { ); }); + it('calculates the highest priority semanticCommitType', () => { + const branch = [ + { + ...requiredDefaultOptions, + manager: 'some-manager', + depName: 'some-dep', + semanticCommits: 'enabled', + semanticCommitType: 'chore', + semanticCommitScope: 'package', + newValue: '1.2.0', + isSingleVersion: true, + newVersion: '1.2.0', + branchName: 'some-branch', + }, + { + ...requiredDefaultOptions, + manager: 'some-manager', + depName: 'some-dep', + semanticCommits: 'enabled', + semanticCommitType: 'feat', + semanticCommitScope: 'package', + newValue: '1.2.0', + isSingleVersion: true, + newVersion: '1.2.0', + branchName: 'some-branch', + }, + { + ...requiredDefaultOptions, + manager: 'some-manager', + depName: 'some-dep', + semanticCommits: 'enabled', + semanticCommitType: 'fix', + semanticCommitScope: 'package', + newValue: '1.2.0', + isSingleVersion: true, + newVersion: '1.2.0', + branchName: 'some-branch', + }, + ] satisfies BranchUpgradeConfig[]; + const res = generateBranchConfig(branch); + expect(res.prTitle).toBe( + 'feat(package): update dependency some-dep to v1.2.0', + ); + expect(res.commitMessage).toBe( + 'feat(package): update dependency some-dep to v1.2.0', + ); + }); + it('scopes monorepo commits', () => { const branch = [ { diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 234e20e40a9185..f2637f2fb95a66 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -159,6 +159,9 @@ function compilePrTitle( logger.trace(`prTitle: ` + JSON.stringify(upgrade.prTitle)); } +// Sorted by priority, from low to high +const semanticCommitTypeByPriority = ['chore', 'ci', 'build', 'fix', 'feat']; + export function generateBranchConfig( upgrades: BranchUpgradeConfig[], ): BranchConfig { @@ -355,6 +358,30 @@ export function generateBranchConfig( releaseTimestamp: releaseTimestamp!, }; // TODO: fixme (#9666) + // Enable `semanticCommits` if one of the branches has it enabled + if ( + config.upgrades.some((upgrade) => upgrade.semanticCommits === 'enabled') + ) { + config.semanticCommits = 'enabled'; + // Calculate the highest priority `semanticCommitType` + let highestIndex = -1; + for (const upgrade of config.upgrades) { + if (upgrade.semanticCommits === 'enabled' && upgrade.semanticCommitType) { + const priorityIndex = semanticCommitTypeByPriority.indexOf( + upgrade.semanticCommitType, + ); + + if (priorityIndex > highestIndex) { + highestIndex = priorityIndex; + } + } + } + + if (highestIndex > -1) { + config.semanticCommitType = semanticCommitTypeByPriority[highestIndex]; + } + } + // Use templates to generate strings const commitMessage = compileCommitMessage(config); compilePrTitle(config, commitMessage);