From 9b3ea98035d9b7609bb071fea6489a235f600017 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 22:30:54 +0000 Subject: [PATCH 1/7] chore(pre-commit): autoupdate hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/bandit: 1.8.0 → 1.8.2](https://github.com/pycqa/bandit/compare/1.8.0...1.8.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 844af72..695b89a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,7 +32,7 @@ repos: - python - repo: https://github.com/pycqa/bandit - rev: 1.8.0 + rev: 1.8.2 hooks: - id: bandit args: ["-ll"] From 7d271fb73dfe42cbdfd3d4e7670cffc4f7f57ed3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Feb 2025 21:04:53 +0000 Subject: [PATCH 2/7] chore(pre-commit): autoupdate hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 24.10.0 → 25.1.0](https://github.com/psf/black/compare/24.10.0...25.1.0) - [github.com/PyCQA/flake8: 7.1.1 → 7.1.2](https://github.com/PyCQA/flake8/compare/7.1.1...7.1.2) - [github.com/pycqa/bandit: 1.8.2 → 1.8.3](https://github.com/pycqa/bandit/compare/1.8.2...1.8.3) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 695b89a..3be9bc1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,21 +18,21 @@ repos: - id: check-added-large-files - repo: https://github.com/psf/black - rev: 24.10.0 + rev: 25.1.0 hooks: - id: black types: - python - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.1.2 hooks: - id: flake8 types: - python - repo: https://github.com/pycqa/bandit - rev: 1.8.2 + rev: 1.8.3 hooks: - id: bandit args: ["-ll"] From e8a7632fe5ca664ff2f8733c3ed280055facabf3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Mar 2025 19:42:21 +0000 Subject: [PATCH 3/7] chore(pre-commit): autoupdate hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/PyCQA/flake8: 7.1.2 → 7.2.0](https://github.com/PyCQA/flake8/compare/7.1.2...7.2.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3be9bc1..247def5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - python - repo: https://github.com/PyCQA/flake8 - rev: 7.1.2 + rev: 7.2.0 hooks: - id: flake8 types: From 347f0ed1f4a4295db34ca8f4fcee8c3ea39cf731 Mon Sep 17 00:00:00 2001 From: bagowix Date: Tue, 29 Apr 2025 22:30:23 +0300 Subject: [PATCH 4/7] fix: skip merge commits patterns --- conventional_pre_commit/format.py | 11 ++++++++--- tests/test_format.py | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/conventional_pre_commit/format.py b/conventional_pre_commit/format.py index 3eab9e3..e4023a2 100644 --- a/conventional_pre_commit/format.py +++ b/conventional_pre_commit/format.py @@ -70,11 +70,16 @@ def has_autosquash_prefix(self, commit_msg: str = ""): def is_merge(self, commit_msg: str = ""): """ - Returns True if input starts with "Merge branch" - See the documentation, please https://git-scm.com/docs/git-merge. + Returns True if the commit message indicates a merge commit. + Matches messages that start with "Merge", including: + - Merge branch ... + - Merge pull request ... + - Merge remote-tracking branch ... + - Merge tag ... + See https://git-scm.com/docs/git-merge. """ commit_msg = self.clean(commit_msg) - return commit_msg.lower().startswith("merge branch ") + return bool(re.match(r"^merge\b", commit_msg.lower())) class ConventionalCommit(Commit): diff --git a/tests/test_format.py b/tests/test_format.py index 6ad99eb..a46005b 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -397,8 +397,16 @@ def test_has_autosquash_prefix(commit, input, expected_result): [ ("Merge branch '2.x.x' into '1.x.x'", True), ("merge branch 'dev' into 'main'", True), + ("Merge remote-tracking branch 'origin/master'", True), + ("Merge pull request #123 from user/feature-branch", True), + ("Merge tag 'v1.2.3' into main", True), + ("Merge origin/master into develop", True), + ("Merge refs/heads/main into develop", True), ("nope not a merge commit", False), ("type: subject", False), + ("fix: merge bug in auth logic", False), + ("chore: merged upstream changes", False), + ("MergeSort implemented and tested", False), ], ) def test_is_merge_commit(input, expected_result): From 669cd460562ee5a06236f9037889a81d9abeb8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20R=C3=A4sch?= Date: Sat, 3 May 2025 20:20:00 +0200 Subject: [PATCH 5/7] test: add validity tests for uppercase types --- tests/test_format.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_format.py b/tests/test_format.py index a46005b..5a1dcec 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -565,6 +565,13 @@ def test_is_valid__default_type(conventional_commit, type): assert conventional_commit.is_valid(input) +@pytest.mark.parametrize("type", ConventionalCommit.DEFAULT_TYPES) +def test_is_valid__default_type_uppercase(conventional_commit, type): + input = f"{type.upper()}: message" + + assert conventional_commit.is_valid(input) + + @pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES) def test_is_valid__conventional_type(conventional_commit, type): input = f"{type}: message" @@ -572,6 +579,13 @@ def test_is_valid__conventional_type(conventional_commit, type): assert conventional_commit.is_valid(input) +@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES) +def test_is_valid__conventional_type_uppercase(conventional_commit, type): + input = f"{type.upper()}: message" + + assert conventional_commit.is_valid(input) + + @pytest.mark.parametrize("type", CUSTOM_TYPES) def test_is_valid__custom_type(type): input = f"{type}: message" @@ -588,6 +602,14 @@ def test_is_valid__conventional_custom_type(type): assert conventional_commits.is_valid(input) +@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES) +def test_is_valid__conventional_custom_type_uppercase(type): + input = f"{type.upper()}: message" + conventional_commits = ConventionalCommit(types=CUSTOM_TYPES) + + assert conventional_commits.is_valid(input) + + def test_is_valid__breaking_change(conventional_commit): input = "fix!: message" From 9d18c1c251a2acf8d53bddee011d6454011ce0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20R=C3=A4sch?= Date: Sat, 3 May 2025 20:51:37 +0200 Subject: [PATCH 6/7] test: add validity test for uppercase scopes --- tests/test_format.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_format.py b/tests/test_format.py index 5a1dcec..97e207d 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -459,6 +459,20 @@ def test_r_scope__scopes(conventional_commit_scope_required): assert not regex.match("(api; client)") +def test_r_scope__scopes_uppercase(conventional_commit_scope_required): + conventional_commit_scope_required.scopes = ["api", "client"] + regex = re.compile(conventional_commit_scope_required.r_scope) + + assert regex.match("(API)") + assert regex.match("(CLIENT)") + assert regex.match("(API, CLIENT)") + assert regex.match("(API: CLIENT)") + assert regex.match("(API/CLIENT)") + assert regex.match("(API-CLIENT)") + assert not regex.match("(TEST)") + assert not regex.match("(API; CLIENT)") + + def test_r_delim(conventional_commit): regex = re.compile(conventional_commit.r_delim) From 039089d1361a27f6e3e540fb197b990f4fdbc4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20R=C3=A4sch?= Date: Sat, 3 May 2025 20:52:41 +0200 Subject: [PATCH 7/7] fix: make types and scopes case-insensitive The conventional commits specification requires implementations not to treat units of information (other than "BREAKING CHANGE") as case-sensitive. --- conventional_pre_commit/format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conventional_pre_commit/format.py b/conventional_pre_commit/format.py index e4023a2..f19f0af 100644 --- a/conventional_pre_commit/format.py +++ b/conventional_pre_commit/format.py @@ -121,7 +121,7 @@ def __init__( @property def r_types(self): """Regex str for valid types.""" - return self._r_or(self.types) + return f"(?i:{self._r_or(self.types)})" @property def r_scope(self): @@ -130,7 +130,7 @@ def r_scope(self): scopes = self._r_or(self.scopes) escaped_delimiters = list(map(re.escape, [":", ",", "-", "/"])) # type: ignore delimiters_pattern = self._r_or(escaped_delimiters) - scope_pattern = rf"\(\s*(?:{scopes})(?:\s*(?:{delimiters_pattern})\s*(?:{scopes}))*\s*\)" + scope_pattern = rf"\(\s*(?:(?i:{scopes}))(?:\s*(?:{delimiters_pattern})\s*(?:(?i:{scopes})))*\s*\)" if self.scope_optional: return f"(?:{scope_pattern})?"