The Unified and Autonomous Development Platform
fix: conventional commits: regex improvements for summary (#1401)
Robin Shen8290cf518e4a
diff --git a/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java b/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.javaindex 4991f27445..d051dab228 100644--- a/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java+++ b/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java@@ -41,7 +41,7 @@ public class BranchProtection implements Serializable {private static final long serialVersionUID = 1L;private static final Pattern CONVENTIONAL_COMMIT_SUBJECT = Pattern.compile(- "(([\\w\\-.]+)\\s*(\\(([\\w\\s\\-./,]+)\\)\\s*)?(!\\s*)?:.+)|(revert\\s+\".*\")",+ "^(([\\w\\-.]+)(\\(([\\w\\-./]+)\\))?!?: [^ ].+)|^(revert \".*\")",UNICODE_CHARACTER_CLASS | CASE_INSENSITIVE);private boolean enabled = true;diff --git a/server-core/src/test/java/io/onedev/server/model/support/code/BranchProtectionTest.java b/server-core/src/test/java/io/onedev/server/model/support/code/BranchProtectionTest.javaindex 08c76c0972..355b9bb3ac 100644--- a/server-core/src/test/java/io/onedev/server/model/support/code/BranchProtectionTest.java+++ b/server-core/src/test/java/io/onedev/server/model/support/code/BranchProtectionTest.java@@ -14,13 +14,22 @@ public class BranchProtectionTest {branchProtection.setCommitTypes(Lists.newArrayList("feat", "bug"));branchProtection.setCommitScopes(Lists.newArrayList("docs", "api"));branchProtection.setMaxCommitMessageLineLength(80);- assertNull(branchProtection.checkCommitMessage("feat:hello world", false));- assertNull(branchProtection.checkCommitMessage("feat ! :hello world", false));- assertNull(branchProtection.checkCommitMessage("feat(docs):hello world", false));- assertNull(branchProtection.checkCommitMessage("feat(docs)!:hello world", false));- assertNull(branchProtection.checkCommitMessage("feat ( docs/api ) ! :hello world", false));- assertNull(branchProtection.checkCommitMessage("feat ( docs , api ) ! :hello world", false));- assertNull(branchProtection.checkCommitMessage("feat:hello world\n\nbody", false));+ assertNull(branchProtection.checkCommitMessage("Revert \"hello world\"", false));+ assertNotNull(branchProtection.checkCommitMessage("revert \"hello world\"", false));+ assertNull(branchProtection.checkCommitMessage("feat: hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat2: hello world", false));+ assertNull(branchProtection.checkCommitMessage("feat(docs): hello world", false));+ assertNull(branchProtection.checkCommitMessage("feat(docs)!: hello world", false));+ assertNull(branchProtection.checkCommitMessage("feat(docs/api)!: hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat(docs2)!: hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat(docs)!: hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat:hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat ! :hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat(docs):hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat(docs)!:hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat ( docs/api ) ! :hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat ( docs , api ) ! :hello world", false));+ assertNotNull(branchProtection.checkCommitMessage("feat:hello world\n\nbody", false));assertNull(branchProtection.checkCommitMessage("hello world", true));assertNull(branchProtection.checkCommitMessage("fix(ä): ö", true));assertNotNull(branchProtection.checkCommitMessage("feat ( docs/api ) ! hello world", false));