From cdec1a0c7ee3af488062d2c3f4c3d22973a2bf76 Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Fri, 30 May 2025 12:37:11 +0800 Subject: [PATCH] refactor(conventional_commits): make schema_pattern more readable --- .../conventional_commits.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 912770a72..441580c1b 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -174,11 +174,27 @@ def schema(self) -> str: ) def schema_pattern(self) -> str: + change_types = ( + "build", + "bump", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test", + ) return ( r"(?s)" # To explicitly make . match new line - r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" # type - r"(\(\S+\))?!?:" # scope - r"( [^\n\r]+)" # subject + r"(" + "|".join(change_types) + r")" # type + r"(\(\S+\))?" # scope + r"!?" + r": " + r"([^\n\r]+)" # subject r"((\n\n.*)|(\s*))?$" )