Skip to content

Commit

Permalink
Merge pull request #157 from github/empty-reports
Browse files Browse the repository at this point in the history
always print the title and search query
  • Loading branch information
zkoppert authored Oct 27, 2023
2 parents b84e454 + 282b16d commit 9291773
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
18 changes: 10 additions & 8 deletions markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ def write_to_markdown(
"""
columns = get_non_hidden_columns(labels)

# If all the metrics are None, then there are no issues
if not issues_with_metrics or len(issues_with_metrics) == 0:
with open("issue_metrics.md", "w", encoding="utf-8") as file:
file.write("no issues found for the given search criteria\n\n")
return

# Sort the issues by time to first response
with open("issue_metrics.md", "w", encoding="utf-8") as file:
file.write("# Issue Metrics\n\n")

# If all the metrics are None, then there are no issues
if not issues_with_metrics or len(issues_with_metrics) == 0:
file.write("no issues found for the given search criteria\n\n")
file.write(
"\n_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
)
if search_query:
file.write(f"Search query used to find these items: `{search_query}`\n")
return

# Write first table with overall metrics
write_overall_metrics_tables(
issues_with_metrics,
Expand Down
18 changes: 13 additions & 5 deletions test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import unittest
from datetime import timedelta
from unittest.mock import mock_open, patch
from unittest.mock import call, mock_open, patch

from classes import IssueWithMetrics
from markdown_writer import write_to_markdown
Expand Down Expand Up @@ -219,11 +219,19 @@ def test_write_to_markdown_no_issues(self):
write_to_markdown(None, None, None, None, None, None, None)

# Check that the file was written correctly
expected_output = "no issues found for the given search criteria\n\n"
mock_open_file.assert_called_once_with(
"issue_metrics.md", "w", encoding="utf-8"
expected_output = [
"# Issue Metrics\n\n",
"no issues found for the given search criteria\n\n",
"\n_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n",
]
# Check that the markdown file was written with the three calls in expected output
mock_open_file.assert_has_calls(
[
call().write(expected_output[0]),
call().write(expected_output[1]),
call().write(expected_output[2]),
]
)
mock_open_file().write.assert_called_once_with(expected_output)


class TestWriteToMarkdownWithEnv(unittest.TestCase):
Expand Down

0 comments on commit 9291773

Please sign in to comment.