mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-25 14:06:27 +00:00
feat: calculate semanticCommitType
priority (#32069)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
parent
6690a6ec34
commit
c41e345e49
2 changed files with 75 additions and 0 deletions
|
@ -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 = [
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue