Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate semanticCommitType priority #32069

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
48 changes: 48 additions & 0 deletions lib/workers/repository/updates/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
30 changes: 30 additions & 0 deletions lib/workers/repository/updates/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -355,6 +358,33 @@ 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';
}
rarkins marked this conversation as resolved.
Show resolved Hide resolved

if (config.semanticCommits === 'enabled') {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
// 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];
}
}

breadadams marked this conversation as resolved.
Show resolved Hide resolved
// Use templates to generate strings
const commitMessage = compileCommitMessage(config);
compilePrTitle(config, commitMessage);
Expand Down