From e3d474b0dcc143883fcdc52d99f2bf3841a05766 Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sat, 17 May 2025 20:42:34 +0800 Subject: [PATCH] refactor: misc cleanup --- .../conventional_commits.py | 21 +++++++------------ commitizen/cz/jira/jira.py | 6 ++---- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index c7b88258cb..3b37e0f7d8 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -41,7 +41,7 @@ class ConventionalCommitsCz(BaseCommitizen): changelog_pattern = defaults.bump_pattern def questions(self) -> Questions: - questions: Questions = [ + return [ { "type": "list", "name": "prefix", @@ -146,7 +146,6 @@ def questions(self) -> Questions: ), }, ] - return questions def message(self, answers: dict) -> str: prefix = answers["prefix"] @@ -165,9 +164,7 @@ def message(self, answers: dict) -> str: if footer: footer = f"\n\n{footer}" - message = f"{prefix}{scope}: {subject}{body}{footer}" - - return message + return f"{prefix}{scope}: {subject}{body}{footer}" def example(self) -> str: return ( @@ -188,25 +185,21 @@ def schema(self) -> str: ) def schema_pattern(self) -> str: - PATTERN = ( + return ( r"(?s)" # To explicitly make . match new line r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" # type r"(\(\S+\))?!?:" # scope r"( [^\n\r]+)" # subject r"((\n\n.*)|(\s*))?$" ) - return PATTERN def info(self) -> str: dir_path = os.path.dirname(os.path.realpath(__file__)) filepath = os.path.join(dir_path, "conventional_commits_info.txt") with open(filepath, encoding=self.config.settings["encoding"]) as f: - content = f.read() - return content + return f.read() def process_commit(self, commit: str) -> str: - pat = re.compile(self.schema_pattern()) - m = re.match(pat, commit) - if m is None: - return "" - return m.group(3).strip() + if m := re.match(self.schema_pattern(), commit): + return m.group(3).strip() + return "" diff --git a/commitizen/cz/jira/jira.py b/commitizen/cz/jira/jira.py index b8fd056a71..f43de2177c 100644 --- a/commitizen/cz/jira/jira.py +++ b/commitizen/cz/jira/jira.py @@ -8,7 +8,7 @@ class JiraSmartCz(BaseCommitizen): def questions(self) -> Questions: - questions = [ + return [ { "type": "input", "name": "message", @@ -42,7 +42,6 @@ def questions(self) -> Questions: "filter": lambda x: "#comment " + x if x else "", }, ] - return questions def message(self, answers: dict) -> str: return " ".join( @@ -77,5 +76,4 @@ def info(self) -> str: dir_path = os.path.dirname(os.path.realpath(__file__)) filepath = os.path.join(dir_path, "jira_info.txt") with open(filepath, encoding=self.config.settings["encoding"]) as f: - content = f.read() - return content + return f.read()