From 6e3fcf8b148aff45bf2c1114214ff63f2de37972 Mon Sep 17 00:00:00 2001 From: Ajesh Sen Thapa Date: Wed, 12 Nov 2025 19:32:16 +0545 Subject: [PATCH] fix: check only first line for ignoring auto generated commits --- src/commitlint/constants.py | 3 ++- src/commitlint/git_helpers.py | 2 ++ src/commitlint/linter/utils.py | 3 ++- tests/fixtures/linter.py | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/commitlint/constants.py b/src/commitlint/constants.py index 499fcd7..6e90fdc 100644 --- a/src/commitlint/constants.py +++ b/src/commitlint/constants.py @@ -25,5 +25,6 @@ r"^Merge remote-tracking branch(\s*)(.*)$|" r"^Automatic merge(.*)$|" r"^Auto-merged (.*?) into (.*)$|" - r"[Bb]ump [^\s]+ from [^\s]+ to [^\s]+" + r"[Bb]ump [^\s]+ from [^\s]+ to [^\s]+|" + r"^[Ii]nitial [Cc]ommit$" ) diff --git a/src/commitlint/git_helpers.py b/src/commitlint/git_helpers.py index 36ef524..05fc458 100644 --- a/src/commitlint/git_helpers.py +++ b/src/commitlint/git_helpers.py @@ -34,6 +34,7 @@ def get_commit_message_of_hash(commit_hash: str) -> str: stderr=subprocess.PIPE, ).strip() console.verbose(commit_message) + console.verbose("execute complete") return commit_message except subprocess.CalledProcessError as ex: @@ -91,6 +92,7 @@ def get_commit_messages_of_hash_range( stderr=subprocess.PIPE, ) console.verbose(commit_messages_output) + console.verbose("execute complete") commit_messages = commit_messages_output.split(f"{delimiter}\n") return [from_commit_message] + [ diff --git a/src/commitlint/linter/utils.py b/src/commitlint/linter/utils.py index ef4c0ca..883d3bd 100644 --- a/src/commitlint/linter/utils.py +++ b/src/commitlint/linter/utils.py @@ -21,7 +21,8 @@ def is_ignored(commit_message: str) -> bool: Returns: bool: True if the commit message should be ignored, False otherwise. """ - return bool(re.match(IGNORE_COMMIT_PATTERNS, commit_message)) + commit_first_line = commit_message.splitlines()[0] + return bool(re.match(IGNORE_COMMIT_PATTERNS, commit_first_line)) def remove_comments(commit_message: str) -> str: diff --git a/tests/fixtures/linter.py b/tests/fixtures/linter.py index 4e2bcee..b800585 100644 --- a/tests/fixtures/linter.py +++ b/tests/fixtures/linter.py @@ -47,6 +47,11 @@ ("feat!: breaking feature", True, []), # ignored commits (success) ("Merge pull request #123", True, []), + ( + "Merge branch 'main' into release\nthis is second line", + True, + [], + ), ("Bump urllib3 from 1.26.5 to 1.26.17", True, []), ("Bump github.com/ollama/ollama from 0.1.48 to 0.2.0", True, []), ("bump @babel/traverse from 7.22.17 to 7.24.0", True, []), @@ -55,6 +60,8 @@ True, [], ), + ("Initial commit", True, []), + ("initial Commit", True, []), # incorrect format check ("feat add new feature", False, [INCORRECT_FORMAT_ERROR]), # header length check