diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9f9bcfb2e..72562457c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v2.29.0 # automatically updated by Commitizen + rev: v2.29.1 # automatically updated by Commitizen hooks: - id: commitizen stages: [commit-msg] diff --git a/CHANGELOG.md b/CHANGELOG.md index f26984291..0606c5e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ +## v2.29.1 (2022-07-26) + +### Fix + +- **Check**: process empty commit message +- **ConventionalCommitsCz**: cz's schema validates the whole commit message now + +### Refactor + +- **Check**: remove the extra preprocessing of commit message file + ## v2.29.0 (2022-07-22) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index ccaf0f033..c626af7be 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.29.0" +__version__ = "2.29.1" diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index fb79e805d..eed3ffbb4 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -82,20 +82,18 @@ def __call__(self): out.success("Commit validation: successful!") def _get_commits(self): + msg = None # Get commit message from file (--commit-msg-file) if self.commit_msg_file is not None: # Enter this branch if commit_msg_file is "". with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: msg = commit_file.read() - msg = self._filter_comments(msg) - msg = msg.lstrip("\n") - commit_title = msg.split("\n")[0] - commit_body = "\n".join(msg.split("\n")[1:]) - return [git.GitCommit(rev="", title=commit_title, body=commit_body)] + # Get commit message from command line (--message) elif self.commit_msg is not None: - # Enter this branch if commit_msg is "". - self.commit_msg = self._filter_comments(self.commit_msg) - return [git.GitCommit(rev="", title="", body=self.commit_msg)] + msg = self.commit_msg + if msg is not None: + msg = self._filter_comments(msg) + return [git.GitCommit(rev="", title="", body=msg)] # Get commit messages from git log (--rev-range) return git.get_commits(end=self.rev_range) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 285f2c144..7989a1712 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -191,8 +191,11 @@ def schema(self) -> str: def schema_pattern(self) -> str: PATTERN = ( - r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" - r"(\(\S+\))?!?:(\s.*)" + r"(?s)" # To explictly make . match new line + r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" # type + r"(\(\S+\))?!?:" # scope + r"( [^\n\r]+)" # subject + r"((\n\n.*)|(\s*))?$" ) return PATTERN diff --git a/pyproject.toml b/pyproject.toml index a832db6db..dadb84aa0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.29.0" +version = "2.29.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -30,7 +30,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.29.0" +version = "2.29.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index e5f62d0a8..6fbbf322c 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -17,20 +17,20 @@ "refactor(git): remove unnecessary dot between git range", "bump: version 1.16.3 → 1.16.4", ( - "Merge pull request #139 from Lee-W/fix-init-clean-config-file\n" + "Merge pull request #139 from Lee-W/fix-init-clean-config-file\n\n" "Fix init clean config file" ), "ci(pyproject.toml): add configuration for coverage", - "fix(commands/init): fix clean up file when initialize commitizen config\n#138", + "fix(commands/init): fix clean up file when initialize commitizen config\n\n#138", "refactor(defaults): split config files into long term support and deprecated ones", "bump: version 1.16.2 → 1.16.3", ( - "Merge pull request #136 from Lee-W/remove-redundant-readme\n" + "Merge pull request #136 from Lee-W/remove-redundant-readme\n\n" "Remove redundant readme" ), "fix: replace README.rst with docs/README.md in config files", ( - "refactor(docs): remove README.rst and use docs/README.md\n" + "refactor(docs): remove README.rst and use docs/README.md\n\n" "By removing README.rst, we no longer need to maintain " "two document with almost the same content\n" "Github can read docs/README.md as README for the project." @@ -38,10 +38,10 @@ "docs(check): pin pre-commit to v1.16.2", "docs(check): fix pre-commit setup", "bump: version 1.16.1 → 1.16.2", - "Merge pull request #135 from Lee-W/fix-pre-commit-hook\nFix pre commit hook", + "Merge pull request #135 from Lee-W/fix-pre-commit-hook\n\nFix pre commit hook", "docs(check): enforce cz check only whem committing", ( - 'Revert "fix(pre-commit): set pre-commit check stage to commit-msg"\n' + 'Revert "fix(pre-commit): set pre-commit check stage to commit-msg"\n\n' "This reverts commit afc70133e4a81344928561fbf3bb20738dfc8a0b." ), "feat!: add user stuff", @@ -129,6 +129,11 @@ def test_check_conventional_commit_succeeds(mocker, capsys): ( "feat!(lang): removed polish language", "no conventional commit", + ( + "ci: check commit message on merge\n" + "testing with more complex commit mes\n\n" + "age with error" + ), ), ) def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir):