Skip to content

Commit 4ae4010

Browse files
authored
Merge pull request #24 from github/fix-prs
fix:pull request function
2 parents 767512f + 2fed337 commit 4ae4010

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

cleanowners.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

177178
def 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

test_cleanowners.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def test_commit_changes(self, mock_uuid):
2424
mock_repo.default_branch = "main"
2525
mock_repo.ref.return_value.object.sha = "abc123" # Mock SHA for latest commit
2626
mock_repo.create_ref.return_value = True
27-
mock_repo.create_file.return_value = True
27+
mock_repo.file_contents.return_value = MagicMock()
28+
mock_repo.file_contents.update.return_value = True
2829
mock_repo.create_pull.return_value = "MockPullRequest"
2930

3031
title = "Test Title"
@@ -45,12 +46,7 @@ def test_commit_changes(self, mock_uuid):
4546
mock_repo.create_ref.assert_called_once_with(
4647
f"refs/heads/{branch_name}", "abc123"
4748
)
48-
mock_repo.create_file.assert_called_once_with(
49-
path="CODEOWNERS",
50-
message=commit_message,
51-
content=dependabot_file.encode(),
52-
branch=branch_name,
53-
)
49+
mock_repo.file_contents.assert_called_once_with("CODEOWNERS")
5450
mock_repo.create_pull.assert_called_once_with(
5551
title=title,
5652
body=body,

0 commit comments

Comments
 (0)