Skip to content

Commit

Permalink
refactor(cz_customize): return empty string for info, example, schema…
Browse files Browse the repository at this point in the history
… and schema_pattern if not provided
  • Loading branch information
Lee-W committed Nov 10, 2024
1 parent 7dd33ea commit c49e7a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions commitizen/cz/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BaseCommitizen(metaclass=ABCMeta):
template_loader: BaseLoader = PackageLoader("commitizen", "templates")
template_extras: dict[str, Any] = {}

def __init__(self, config: BaseConfig):
def __init__(self, config: BaseConfig) -> None:
self.config = config
if not self.config.settings.get("style"):
self.config.settings.update({"style": BaseCommitizen.default_style_config})
Expand All @@ -83,19 +83,19 @@ def style(self):
]
)

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

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

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

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

Expand Down
16 changes: 8 additions & 8 deletions commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def message(self, answers: dict) -> str:
else:
return message_template.render(**answers)

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

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

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

def info(self) -> str | None:
def info(self) -> str:
info_path = self.custom_settings.get("info_path")
info = self.custom_settings.get("info")
if info_path:
Expand All @@ -86,4 +86,4 @@ def info(self) -> str | None:
return content
elif info:
return info
return None
return ""
2 changes: 1 addition & 1 deletion commitizen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExitCode(enum.IntEnum):
class CommitizenException(Exception):
def __init__(self, *args, **kwargs):
self.output_method = kwargs.get("output_method") or out.error
self.exit_code = self.__class__.exit_code
self.exit_code: ExitCode = self.__class__.exit_code
if args:
self.message = args[0]
elif hasattr(self.__class__, "message"):
Expand Down
10 changes: 5 additions & 5 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ commitizen:
| ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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. |
| `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` |
| `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`. |
| `example` | `str` | `""` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
| `schema` | `str` | `""` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
| `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
| `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. |
| `info` | `str` | `""` | (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`) |
| `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
| `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"]` |
Expand Down

0 comments on commit c49e7a2

Please sign in to comment.