From a2137ac731112d689e07f5fbac3186065f009422 Mon Sep 17 00:00:00 2001 From: bogay Date: Mon, 11 Apr 2022 22:14:44 +0800 Subject: [PATCH 1/6] test(test_check_command): add blank line after subject for `COMMIT_LOG` According to the spec of conventional commits, the body must begin with a blank line after the description. spec: https://www.conventionalcommits.org/en/v1.0.0/#specification --- tests/commands/test_check_command.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index e5f62d0a8..4a9c14153 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", From fc4ebc80ba0ec7019ba1730aa4203d601426c0b0 Mon Sep 17 00:00:00 2001 From: bogay Date: Mon, 11 Apr 2022 23:15:31 +0800 Subject: [PATCH 2/6] test(test_check_command): add multi-line no conventional commit testdata The original cz schema of check the first line. --- tests/commands/test_check_command.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index 4a9c14153..6fbbf322c 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -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): From c2476700bc9bf4cf2f2462dd956a962be14b373c Mon Sep 17 00:00:00 2001 From: bogay Date: Mon, 11 Apr 2022 23:19:49 +0800 Subject: [PATCH 3/6] fix(ConventionalCommitsCz): cz's schema validates the whole commit message now --- commitizen/cz/conventional_commits/conventional_commits.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 From 6493fe2fa10433242110e4f654180a2115b148ce Mon Sep 17 00:00:00 2001 From: bogay Date: Mon, 11 Apr 2022 23:23:05 +0800 Subject: [PATCH 4/6] refactor(Check): remove the extra preprocessing of commit message file --- commitizen/commands/check.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index fb79e805d..fa7a9e974 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() + # Get commit message from command line (--message) + elif self.commit_msg: + msg = self.commit_msg + if msg is not None: 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)] - 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)] + return [git.GitCommit(rev="", title="", body=msg)] # Get commit messages from git log (--rev-range) return git.get_commits(end=self.rev_range) From 1f0177c8274ab119a151989123f0d0a4596c0053 Mon Sep 17 00:00:00 2001 From: bogay Date: Sat, 23 Jul 2022 14:57:02 +0800 Subject: [PATCH 5/6] fix(Check): process empty commit message `elif self.commit_msg` will be skipped if the commit message is empty string, but this should be handled. --- commitizen/commands/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index fa7a9e974..eed3ffbb4 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -89,7 +89,7 @@ def _get_commits(self): with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: msg = commit_file.read() # Get commit message from command line (--message) - elif self.commit_msg: + elif self.commit_msg is not None: msg = self.commit_msg if msg is not None: msg = self._filter_comments(msg) From dee73f09d41ebda9f27dffb363e414f6f9cf8bc2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 26 Jul 2022 03:36:52 +0000 Subject: [PATCH 6/6] =?UTF-8?q?bump:=20version=202.29.0=20=E2=86=92=202.29?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 11 +++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) 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/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"