feat: Able to use conventional commit types configured in branch protection rule for PR title generation (OD-2540)

This commit is contained in:
Robin Shen 2025-08-31 20:06:34 +08:00
parent 1e477e2347
commit 9f3ad0bc11

View File

@ -1406,8 +1406,13 @@ public class PullRequest extends ProjectBelonging
wip = true;
title = title.substring(4);
}
var commitTypes = CONVENTIONAL_COMMIT_TYPES;
var branchProtection = getProject().getBranchProtection(getTargetBranch(), getSubmitter());
if (branchProtection.isEnforceConventionalCommits() && !branchProtection.getCommitTypes().isEmpty()) {
commitTypes = branchProtection.getCommitTypes();
}
boolean found = false;
for (var commitType: CONVENTIONAL_COMMIT_TYPES) {
for (var commitType: commitTypes) {
if (title.startsWith(commitType + "-") || title.startsWith(commitType + "_") || title.startsWith(commitType + "/")) {
title = commitType + ": " + StringUtils.capitalize(title.substring(commitType.length() + 1).replace('-', ' ').replace('_', ' ').replace('/', ' '));
found = true;