Fix file-encoding bugs, broken test mock, missing review context (#749)
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d5d30fc7ce
commit
bb6101bd39
@@ -389,7 +389,7 @@ def run():
|
||||
f"**Repos scanned:** {len(repos)} | **PRs created:** {total_prs_created} | **Skipped:** {total_prs_skipped} | **Actions cached:** {len(cache)}\n",
|
||||
*summary,
|
||||
]
|
||||
with open(summary_file, "a") as f:
|
||||
with open(summary_file, "a", encoding="utf-8") as f:
|
||||
f.write("\n".join(lines))
|
||||
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ def main(*args, **kwargs):
|
||||
if AUTO_PR_REVIEW:
|
||||
print("Starting automatic PR review...")
|
||||
review_number = review_pr.dismiss_previous_reviews(event)
|
||||
review_data = review_pr.generate_pr_review(event.repository, diff, title, summary)
|
||||
review_data = review_pr.generate_pr_review(event.repository, diff, title, summary, event)
|
||||
review_pr.post_review_summary(event, review_data, review_number)
|
||||
print("PR review completed")
|
||||
return
|
||||
|
||||
@@ -125,7 +125,7 @@ def process_markdown_string(
|
||||
with tempfile.TemporaryDirectory() as temp_dir_name:
|
||||
temp_dir = Path(temp_dir_name)
|
||||
temp_md = temp_dir / "input.md"
|
||||
temp_md.write_text(markdown_content)
|
||||
temp_md.write_text(markdown_content, encoding="utf-8")
|
||||
|
||||
markdown_snapshot, temp_files = process_markdown_file(temp_md, temp_dir, process_python, process_bash, verbose)
|
||||
if markdown_snapshot is None or temp_files is None:
|
||||
@@ -140,7 +140,7 @@ def process_markdown_string(
|
||||
format_bash_with_prettier(temp_dir)
|
||||
|
||||
update_markdown_file(temp_md, markdown_snapshot, temp_files)
|
||||
formatted_markdown = temp_md.read_text()
|
||||
formatted_markdown = temp_md.read_text(encoding="utf-8")
|
||||
|
||||
return formatted_markdown
|
||||
|
||||
@@ -159,7 +159,7 @@ def generate_temp_filename(file_path, index, code_type):
|
||||
def process_markdown_file(file_path, temp_dir, process_python=True, process_bash=True, verbose=False):
|
||||
"""Processes a Markdown file, extracting code blocks for formatting and updating the original file."""
|
||||
try:
|
||||
markdown_content = Path(file_path).read_text()
|
||||
markdown_content = Path(file_path).read_text(encoding="utf-8")
|
||||
code_blocks_by_type = extract_code_blocks(markdown_content)
|
||||
temp_files = []
|
||||
|
||||
@@ -179,7 +179,7 @@ def process_markdown_file(file_path, temp_dir, process_python=True, process_bash
|
||||
code_without_indentation = remove_indentation(code_block, num_spaces)
|
||||
temp_file_path = temp_dir / generate_temp_filename(file_path, i + offset, code_type)
|
||||
|
||||
with open(temp_file_path, "w") as temp_file:
|
||||
with open(temp_file_path, "w", encoding="utf-8") as temp_file:
|
||||
temp_file.write(code_without_indentation)
|
||||
|
||||
temp_files.append((num_spaces, code_block, temp_file_path, code_type))
|
||||
@@ -195,7 +195,7 @@ def update_markdown_file(file_path, markdown_content, temp_files):
|
||||
"""Updates a Markdown file with formatted code blocks."""
|
||||
for num_spaces, original_code_block, temp_file_path, code_type in temp_files:
|
||||
try:
|
||||
with open(temp_file_path) as temp_file:
|
||||
with open(temp_file_path, encoding="utf-8") as temp_file:
|
||||
formatted_code = temp_file.read().rstrip("\n") # Strip trailing newlines
|
||||
formatted_code_with_indentation = add_indentation(formatted_code, num_spaces)
|
||||
|
||||
@@ -212,7 +212,7 @@ def update_markdown_file(file_path, markdown_content, temp_files):
|
||||
print(f"Error updating code block in file {file_path}: {e}")
|
||||
|
||||
try:
|
||||
with open(file_path, "w") as file:
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(markdown_content)
|
||||
except Exception as e:
|
||||
print(f"Error writing file {file_path}: {e}")
|
||||
|
||||
@@ -115,11 +115,12 @@ def test_ignore_paths():
|
||||
|
||||
def test_main_real_files():
|
||||
"""Test main function on actual repository files."""
|
||||
# Mock update_file to prevent actual file modifications during testing
|
||||
with patch("actions.update_file_headers.update_file", return_value=False) as mock_update:
|
||||
main()
|
||||
# Verify that update_file was called (indicates file processing occurred)
|
||||
assert mock_update.call_count > 0
|
||||
with patch("actions.update_file_headers.Action") as mock_action:
|
||||
mock_action.return_value.repository = "ultralytics/actions"
|
||||
mock_action.return_value.is_repo_private.return_value = False
|
||||
main()
|
||||
assert mock_update.call_count > 0
|
||||
|
||||
|
||||
def test_main_with_custom_header():
|
||||
|
||||
Reference in New Issue
Block a user