Skip to content

fix: Set default filename, when output file is empty #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,16 @@ def evaluate_markdown_file_size(output_file: str) -> None:
"""
Evaluate the size of the markdown file and split it, if it is too large.
"""
file_name_without_extension = Path(output_file).stem
output_file_name = output_file if output_file else "issue_metrics.md"
file_name_without_extension = Path(output_file_name).stem
max_char_count = 65535
if markdown_too_large_for_issue_body(output_file, max_char_count):
split_markdown_file(output_file, max_char_count)
shutil.move(output_file, f"{file_name_without_extension}_full.md")
shutil.move(f"{file_name_without_extension}_0.md", output_file)
if markdown_too_large_for_issue_body(output_file_name, max_char_count):
split_markdown_file(output_file_name, max_char_count)
shutil.move(output_file_name, f"{file_name_without_extension}_full.md")
shutil.move(f"{file_name_without_extension}_0.md", output_file_name)
print(
f"Issue metrics markdown file is too large for GitHub issue body and has been \
split into multiple files. ie. {output_file}, {file_name_without_extension}_1.md, etc. \
split into multiple files. ie. {output_file_name}, {file_name_without_extension}_1.md, etc. \
The full file is saved as {file_name_without_extension}_full.md\n\
See https://github.com/github/issue-metrics/blob/main/docs/dealing-with-large-issue-metrics.md"
)
Expand Down
12 changes: 12 additions & 0 deletions test_issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,18 @@ def test_get_per_issue_metrics_with_discussion_with_hide_envs(self):
class TestEvaluateMarkdownFileSize(unittest.TestCase):
"""Test suite for the evaluate_markdown_file_size function."""

@patch("issue_metrics.markdown_too_large_for_issue_body")
def test_markdown_too_large_for_issue_body_called_with_empty_output_file(
self, mock_evaluate
):
"""
Test that the function uses the output_file.
"""
mock_evaluate.return_value = False
evaluate_markdown_file_size("")

mock_evaluate.assert_called_with("issue_metrics.md", 65535)

@patch("issue_metrics.markdown_too_large_for_issue_body")
def test_markdown_too_large_for_issue_body_called_with_output_file(
self, mock_evaluate
Expand Down
Loading