Skip to content

Commit c49e7a2

Browse files
committed
refactor(cz_customize): return empty string for info, example, schema and schema_pattern if not provided
1 parent 7dd33ea commit c49e7a2

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

commitizen/cz/base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BaseCommitizen(metaclass=ABCMeta):
6161
template_loader: BaseLoader = PackageLoader("commitizen", "templates")
6262
template_extras: dict[str, Any] = {}
6363

64-
def __init__(self, config: BaseConfig):
64+
def __init__(self, config: BaseConfig) -> None:
6565
self.config = config
6666
if not self.config.settings.get("style"):
6767
self.config.settings.update({"style": BaseCommitizen.default_style_config})
@@ -83,19 +83,19 @@ def style(self):
8383
]
8484
)
8585

86-
def example(self) -> str | None:
86+
def example(self) -> str:
8787
"""Example of the commit message."""
8888
raise NotImplementedError("Not Implemented yet")
8989

90-
def schema(self) -> str | None:
90+
def schema(self) -> str:
9191
"""Schema definition of the commit message."""
9292
raise NotImplementedError("Not Implemented yet")
9393

94-
def schema_pattern(self) -> str | None:
94+
def schema_pattern(self) -> str:
9595
"""Regex matching the schema used for message validation."""
9696
raise NotImplementedError("Not Implemented yet")
9797

98-
def info(self) -> str | None:
98+
def info(self) -> str:
9999
"""Information about the standardized commit message."""
100100
raise NotImplementedError("Not Implemented yet")
101101

commitizen/cz/customize/customize.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ def message(self, answers: dict) -> str:
6868
else:
6969
return message_template.render(**answers)
7070

71-
def example(self) -> str | None:
72-
return self.custom_settings.get("example")
71+
def example(self) -> str:
72+
return self.custom_settings.get("example") or ""
7373

74-
def schema_pattern(self) -> str | None:
75-
return self.custom_settings.get("schema_pattern")
74+
def schema_pattern(self) -> str:
75+
return self.custom_settings.get("schema_pattern") or ""
7676

77-
def schema(self) -> str | None:
78-
return self.custom_settings.get("schema")
77+
def schema(self) -> str:
78+
return self.custom_settings.get("schema") or ""
7979

80-
def info(self) -> str | None:
80+
def info(self) -> str:
8181
info_path = self.custom_settings.get("info_path")
8282
info = self.custom_settings.get("info")
8383
if info_path:
@@ -86,4 +86,4 @@ def info(self) -> str | None:
8686
return content
8787
elif info:
8888
return info
89-
return None
89+
return ""

commitizen/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ExitCode(enum.IntEnum):
4242
class CommitizenException(Exception):
4343
def __init__(self, *args, **kwargs):
4444
self.output_method = kwargs.get("output_method") or out.error
45-
self.exit_code = self.__class__.exit_code
45+
self.exit_code: ExitCode = self.__class__.exit_code
4646
if args:
4747
self.message = args[0]
4848
elif hasattr(self.__class__, "message"):

docs/customization.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ commitizen:
151151
| ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152152
| `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is defined in `commitizen.defaults`. It expects a list of dictionaries. |
153153
| `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2][jinja2] formatting specification, and all the variables in this template should be defined in `name` in `questions` |
154-
| `example` | `str` | `None` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
155-
| `schema` | `str` | `None` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
156-
| `schema_pattern` | `str` | `None` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
157-
| `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. |
158-
| `info` | `str` | `None` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
154+
| `example` | `str` | `""` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
155+
| `schema` | `str` | `""` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
156+
| `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
157+
| `info_path` | `str` | `""` | (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. |
158+
| `info` | `str` | `""` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
159159
| `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
160160
| `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
161161
| `change_type_order`| `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]` |

0 commit comments

Comments
 (0)