@@ -72,12 +72,17 @@ def run(self) -> ExitCode:
72
72
"""
73
73
issue_pattern : str = self .hook_config .get_issue_pattern ()
74
74
issue_or_no_issue_pattern : str = \
75
- "%s|%s" % ( issue_pattern , self .hook_config .get_no_issue_phrase ())
75
+ f" { issue_pattern } | { self .hook_config .get_no_issue_phrase ()} "
76
76
77
77
branch_name : str = self .get_current_branch_name ()
78
78
79
79
commit_msg_file_path : str = os .path .join (self .git_repo_path , self .git_commit_message_path )
80
- raw_commit_msg_text : str = open (commit_msg_file_path , 'r' ).read ()
80
+
81
+ raw_commit_msg_text : str
82
+
83
+ with open (commit_msg_file_path , 'r' , encoding = "utf8" ) as commit_msg_file :
84
+ raw_commit_msg_text = commit_msg_file .read ()
85
+
81
86
commit_msg_text : str = raw_commit_msg_text .splitlines ()[0 ]
82
87
83
88
issue_in_branch : str = get_left_most_issue_in_string (issue_pattern , branch_name )
@@ -117,10 +122,9 @@ def run(self) -> ExitCode:
117
122
issue_in_branch ,
118
123
branch_name )
119
124
120
- commit_msg_text = "%s: %s" % ( issue_in_branch , raw_commit_msg_text )
125
+ commit_msg_text = f" { issue_in_branch } : { raw_commit_msg_text } "
121
126
122
127
# Open file for write, which will empty the file contents
123
- commit_msg_file = open (commit_msg_file_path , 'w' )
124
- commit_msg_file .write (commit_msg_text )
125
- commit_msg_file .close ()
128
+ with open (commit_msg_file_path , 'w' , encoding = "utf8" ) as commit_msg_file :
129
+ commit_msg_file .write (commit_msg_text )
126
130
return ExitCode .SUCCESS
0 commit comments