Skip to content

Commit 9ccabe5

Browse files
yuukidachLee-W
authored andcommitted
fix(check): filter out comment messege when checking
fix #455
1 parent 6ddd68d commit 9ccabe5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

commitizen/commands/check.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,23 @@ def _get_commits(self):
8181
# Get commit message from file (--commit-msg-file)
8282
if self.commit_msg_file:
8383
with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file:
84-
commit_title = commit_file.readline()
85-
commit_body = commit_file.read()
84+
msg = commit_file.read()
85+
msg = self._filter_comments(msg)
86+
msg = msg.lstrip("\n")
87+
commit_title = msg.split("\n")[0]
88+
commit_body = "\n".join(msg.split("\n")[1:])
8689
return [git.GitCommit(rev="", title=commit_title, body=commit_body)]
8790
elif self.commit_msg:
91+
self.commit_msg = self._filter_comments(self.commit_msg)
8892
return [git.GitCommit(rev="", title="", body=self.commit_msg)]
8993

9094
# Get commit messages from git log (--rev-range)
9195
return git.get_commits(end=self.rev_range)
9296

97+
def _filter_comments(self, msg: str) -> str:
98+
lines = [line for line in msg.split('\n') if not line.startswith('#')]
99+
return "\n".join(lines)
100+
93101
@staticmethod
94102
def validate_commit_message(commit_msg: str, pattern: str) -> bool:
95103
if commit_msg.startswith("Merge") or commit_msg.startswith("Revert"):

0 commit comments

Comments
 (0)