The Unified and Autonomous Development Platform
feat: Able to use conventional commit types configured in branch protection rule for PR title generation (OD-2540)
Robin Shen9f3ad0bc1117
diff --git a/server-core/src/main/java/io/onedev/server/model/PullRequest.java b/server-core/src/main/java/io/onedev/server/model/PullRequest.javaindex fe8e0a4e6a..e8f5e3174c 100644--- a/server-core/src/main/java/io/onedev/server/model/PullRequest.java+++ b/server-core/src/main/java/io/onedev/server/model/PullRequest.java@@ -1406,8 +1406,13 @@ public class PullRequest extends ProjectBelongingwip = 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;