Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7fd6ce3

Browse filesBrowse files
bearomorphismLee-W
authored andcommitted
refactor(check): simplify code
1 parent fe72043 commit 7fd6ce3
Copy full SHA for 7fd6ce3

File tree

1 file changed

+12
-15
lines changed
Filter options

1 file changed

+12
-15
lines changed

‎commitizen/commands/check.py

Copy file name to clipboardExpand all lines: commitizen/commands/check.py
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,21 @@ def __call__(self):
8888
)
8989
out.success("Commit validation: successful!")
9090

91+
def _get_commit_message(self) -> str | None:
92+
if self.commit_msg_file is None:
93+
# Get commit message from command line (--message)
94+
return self.commit_msg
95+
96+
with open(self.commit_msg_file, encoding=self.encoding) as commit_file:
97+
# Get commit message from file (--commit-msg-file)
98+
return commit_file.read()
99+
91100
def _get_commits(self):
92-
msg = None
93-
# Get commit message from file (--commit-msg-file)
94-
if self.commit_msg_file is not None:
95-
# Enter this branch if commit_msg_file is "".
96-
with open(self.commit_msg_file, encoding=self.encoding) as commit_file:
97-
msg = commit_file.read()
98-
# Get commit message from command line (--message)
99-
elif self.commit_msg is not None:
100-
msg = self.commit_msg
101-
if msg is not None:
102-
msg = self._filter_comments(msg)
103-
return [git.GitCommit(rev="", title="", body=msg)]
101+
if (msg := self._get_commit_message()) is not None:
102+
return [git.GitCommit(rev="", title="", body=self._filter_comments(msg))]
104103

105104
# Get commit messages from git log (--rev-range)
106-
if self.rev_range:
107-
return git.get_commits(end=self.rev_range)
108-
return git.get_commits()
105+
return git.get_commits(end=self.rev_range or "HEAD")
109106

110107
@staticmethod
111108
def _filter_comments(msg: str) -> str:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.