diff --git a/commitizen/cli.py b/commitizen/cli.py index 3c529e421..8f33f02d3 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -541,7 +541,7 @@ def commitizen_excepthook( original_excepthook(type, value, traceback) exit_code = value.exit_code if exit_code in no_raise: - exit_code = 0 + exit_code = ExitCode.EXPECTED_EXIT sys.exit(exit_code) else: original_excepthook(type, value, traceback) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 13b8555b6..e22155cf7 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -54,7 +54,7 @@ def _valid_command_argument(self): for arg in (self.commit_msg_file, self.commit_msg, self.rev_range) ) if num_exclusive_args_provided == 0 and not sys.stdin.isatty(): - self.commit_msg: str | None = sys.stdin.read() + self.commit_msg = sys.stdin.read() elif num_exclusive_args_provided != 1: raise InvalidCommandArgumentError( "Only one of --rev-range, --message, and --commit-msg-file is permitted by check command! " @@ -107,7 +107,9 @@ def _get_commits(self): return [git.GitCommit(rev="", title="", body=msg)] # Get commit messages from git log (--rev-range) - return git.get_commits(end=self.rev_range) + if self.rev_range: + return git.get_commits(end=self.rev_range) + return git.get_commits() @staticmethod def _filter_comments(msg: str) -> str: diff --git a/commitizen/cz/base.py b/commitizen/cz/base.py index bd116ceb0..70929e2f8 100644 --- a/commitizen/cz/base.py +++ b/commitizen/cz/base.py @@ -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}) @@ -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") diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 5c3b4e76b..b7f49f28d 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -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: @@ -86,4 +86,4 @@ def info(self) -> str | None: return content elif info: return info - return None + return "" diff --git a/commitizen/defaults.py b/commitizen/defaults.py index e4363f4ab..55c287eb2 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -45,7 +45,7 @@ class Settings(TypedDict, total=False): changelog_merge_prerelease: bool update_changelog_on_bump: bool use_shortcuts: bool - style: list[tuple[str, str]] | None + style: list[tuple[str, str]] customize: CzSettings major_version_zero: bool pre_bump_hooks: list[str] | None diff --git a/commitizen/exceptions.py b/commitizen/exceptions.py index c96803b5f..29733b624 100644 --- a/commitizen/exceptions.py +++ b/commitizen/exceptions.py @@ -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"): diff --git a/docs/customization.md b/docs/customization.md index e8f233fce..24ce794dc 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -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"]` | diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index 20a17b3d9..210c8b677 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -564,7 +564,7 @@ def test_info_with_info_path(tmpdir, config_info): def test_info_without_info(config_without_info): cz = CustomizeCommitsCz(config_without_info) - assert cz.info() is None + assert cz.info() == "" def test_commit_parser(config):