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
31 changes: 31 additions & 0 deletions lib/workers/repository/updates/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function compilePrTitle(
logger.trace(`prTitle: ` + JSON.stringify(upgrade.prTitle));
}

const semanticCommitTypePriorities: Record<string, number> = {
feat: 2,
fix: 1,
build: 0,
ci: 0,
chore: 0,
};
rarkins marked this conversation as resolved.
Show resolved Hide resolved

export function generateBranchConfig(
upgrades: BranchUpgradeConfig[],
): BranchConfig {
Expand Down Expand Up @@ -355,6 +363,29 @@ export function generateBranchConfig(
releaseTimestamp: releaseTimestamp!,
}; // TODO: fixme (#9666)

let highestPrioritySemanticCommitType = '';
rarkins marked this conversation as resolved.
Show resolved Hide resolved

for (const upgrade of config.upgrades) {
if (
upgrade.semanticCommits &&
upgrade.semanticCommitType &&
breadadams marked this conversation as resolved.
Show resolved Hide resolved
upgrade.semanticCommitType in semanticCommitTypePriorities
) {
const priority = semanticCommitTypePriorities[upgrade.semanticCommitType];
const highestPriority =
semanticCommitTypePriorities[highestPrioritySemanticCommitType] ?? -1;

if (priority > highestPriority) {
highestPrioritySemanticCommitType = upgrade.semanticCommitType;
}
}
}

if (highestPrioritySemanticCommitType) {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
config.semanticCommitType = highestPrioritySemanticCommitType;
}
config.semanticCommits = config.upgrades.some((upgrade) => upgrade.semanticCommits));
breadadams marked this conversation as resolved.
Show resolved Hide resolved

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