Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

fix(cz_customize): make schema_pattern customizable through config for cz_customize #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<type>: <body>"
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"
Expand Down Expand Up @@ -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`) |
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cz_customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<type>: <body>"
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."
Expand Down Expand Up @@ -114,6 +116,11 @@ def test_schema(config):
assert "<type>: <body>" 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()
Expand Down