@@ -94,8 +94,9 @@ def main(): # pragma: no cover
9494 if not dry_run :
9595 # Remove that username from the codeowners_file_contents
9696 file_changed = True
97- codeowners_file_contents = codeowners_file_contents .decoded .replace (
98- f"@{ username } " , ""
97+ bytes_username = f"@{ username } " .encode ("ASCII" )
98+ codeowners_file_contents_new = (
99+ codeowners_file_contents .decoded .replace (bytes_username , b"" )
99100 )
100101
101102 # Update the CODEOWNERS file if usernames were removed
@@ -106,7 +107,7 @@ def main(): # pragma: no cover
106107 title ,
107108 body ,
108109 repo ,
109- codeowners_file_contents ,
110+ codeowners_file_contents_new ,
110111 commit_message ,
111112 codeowners_filepath ,
112113 )
@@ -175,7 +176,12 @@ def get_usernames_from_codeowners(codeowners_file_contents):
175176
176177
177178def commit_changes (
178- title , body , repo , codeowners_file_contents , commit_message , codeowners_filepath
179+ title ,
180+ body ,
181+ repo ,
182+ codeowners_file_contents_new ,
183+ commit_message ,
184+ codeowners_filepath ,
179185):
180186 """Commit the changes to the repo and open a pull reques and return the pull request object"""
181187 default_branch = repo .default_branch
@@ -184,10 +190,9 @@ def commit_changes(
184190 front_matter = "refs/heads/"
185191 branch_name = "codeowners-" + str (uuid .uuid4 ())
186192 repo .create_ref (front_matter + branch_name , default_branch_commit )
187- repo .create_file (
188- path = codeowners_filepath ,
193+ repo .file_contents (codeowners_filepath ).update (
189194 message = commit_message ,
190- content = codeowners_file_contents . encode (), # Convert to bytes object
195+ content = codeowners_file_contents_new ,
191196 branch = branch_name ,
192197 )
193198
0 commit comments