From 5b56b7e2f9c357cf5ec0b439e6f7b398a5e9aa4d Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 4 Oct 2020 12:14:42 +0800 Subject: [PATCH] fix(cz_customize): make schema_pattern customiziable through config for cz_customize --- commitizen/cz/customize/customize.py | 3 +++ docs/customization.md | 2 ++ tests/test_cz_customize.py | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 122dc9a4ee..1c0bb98baf 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -45,6 +45,9 @@ def message(self, answers: dict) -> str: def example(self) -> Optional[str]: return self.custom_settings.get("example") + def schema_pattern(self) -> Optional[str]: + return self.custom_settings.get("schema_pattern") + def schema(self) -> Optional[str]: return self.custom_settings.get("schema") diff --git a/docs/customization.md b/docs/customization.md index 0602b9cecb..2478bdc5f7 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -20,6 +20,7 @@ name = "cz_customize" message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" example = "feature: this feature enable customize through config file" schema = ": " +schema_pattern = "(feature|bug fix):(\\s.*)" bump_pattern = "^(break|new|fix|hotfix)" bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} info_path = "cz_customize_info.txt" @@ -53,6 +54,7 @@ message = "Do you want to add body message in commit?" | `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow the [string.Template](https://docs.python.org/3/library/string.html#template-strings) or [Jinja2](https://jinja.palletsprojects.com/en/2.10.x/) formatting specification, and all the variables in this template should be defined in `name` in `questions`. Note that `Jinja2` is not installed by default. If not installed, commitizen will use `string.Template` formatting. | | `example` | `str` | `None` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. | | `schema` | `str` | `None` | (OPTIONAL) Show the schema used. Used by `cz schema`. | +| `schema_pattern` | `str` | `None` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. | | `info_path` | `str` | `None` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. | | `info` | `str` | `None` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. | | `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) | diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index 11b14ab596..2cf0a5917d 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -12,6 +12,8 @@ def config(): message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" example = "feature: this feature enable customize through config file" schema = ": " + schema_pattern = "(feature|bug fix):(\\s.*)" + bump_pattern = "^(break|new|fix|hotfix)" bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} info = "This is a customized cz." @@ -114,6 +116,11 @@ def test_schema(config): assert ": " in cz.schema() +def test_schema_pattern(config): + cz = CustomizeCommitsCz(config) + assert r"(feature|bug fix):(\s.*)" in cz.schema_pattern() + + def test_info(config): cz = CustomizeCommitsCz(config) assert "This is a customized cz." in cz.info()