Skip to content

Commit d4867b0

Browse files
authored
fix: check only first line for ignoring auto generated commits (#80)
1 parent 7d51774 commit d4867b0

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/commitlint/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
r"^Merge remote-tracking branch(\s*)(.*)$|"
2626
r"^Automatic merge(.*)$|"
2727
r"^Auto-merged (.*?) into (.*)$|"
28-
r"[Bb]ump [^\s]+ from [^\s]+ to [^\s]+"
28+
r"[Bb]ump [^\s]+ from [^\s]+ to [^\s]+|"
29+
r"^[Ii]nitial [Cc]ommit$"
2930
)

src/commitlint/git_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_commit_message_of_hash(commit_hash: str) -> str:
3434
stderr=subprocess.PIPE,
3535
).strip()
3636
console.verbose(commit_message)
37+
console.verbose("execute complete")
3738

3839
return commit_message
3940
except subprocess.CalledProcessError as ex:
@@ -91,6 +92,7 @@ def get_commit_messages_of_hash_range(
9192
stderr=subprocess.PIPE,
9293
)
9394
console.verbose(commit_messages_output)
95+
console.verbose("execute complete")
9496

9597
commit_messages = commit_messages_output.split(f"{delimiter}\n")
9698
return [from_commit_message] + [

src/commitlint/linter/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def is_ignored(commit_message: str) -> bool:
2121
Returns:
2222
bool: True if the commit message should be ignored, False otherwise.
2323
"""
24-
return bool(re.match(IGNORE_COMMIT_PATTERNS, commit_message))
24+
commit_first_line = commit_message.splitlines()[0]
25+
return bool(re.match(IGNORE_COMMIT_PATTERNS, commit_first_line))
2526

2627

2728
def remove_comments(commit_message: str) -> str:

tests/fixtures/linter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
("feat!: breaking feature", True, []),
4848
# ignored commits (success)
4949
("Merge pull request #123", True, []),
50+
(
51+
"Merge branch 'main' into release\nthis is second line",
52+
True,
53+
[],
54+
),
5055
("Bump urllib3 from 1.26.5 to 1.26.17", True, []),
5156
("Bump github.com/ollama/ollama from 0.1.48 to 0.2.0", True, []),
5257
("bump @babel/traverse from 7.22.17 to 7.24.0", True, []),
@@ -55,6 +60,8 @@
5560
True,
5661
[],
5762
),
63+
("Initial commit", True, []),
64+
("initial Commit", True, []),
5865
# incorrect format check
5966
("feat add new feature", False, [INCORRECT_FORMAT_ERROR]),
6067
# header length check

0 commit comments

Comments
 (0)