Skip to content

Commit 9291773

Browse files
authored
Merge pull request #157 from github/empty-reports
always print the title and search query
2 parents b84e454 + 282b16d commit 9291773

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

markdown_writer.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,19 @@ def write_to_markdown(
102102
103103
"""
104104
columns = get_non_hidden_columns(labels)
105-
106-
# If all the metrics are None, then there are no issues
107-
if not issues_with_metrics or len(issues_with_metrics) == 0:
108-
with open("issue_metrics.md", "w", encoding="utf-8") as file:
109-
file.write("no issues found for the given search criteria\n\n")
110-
return
111-
112-
# Sort the issues by time to first response
113105
with open("issue_metrics.md", "w", encoding="utf-8") as file:
114106
file.write("# Issue Metrics\n\n")
115107

108+
# If all the metrics are None, then there are no issues
109+
if not issues_with_metrics or len(issues_with_metrics) == 0:
110+
file.write("no issues found for the given search criteria\n\n")
111+
file.write(
112+
"\n_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
113+
)
114+
if search_query:
115+
file.write(f"Search query used to find these items: `{search_query}`\n")
116+
return
117+
116118
# Write first table with overall metrics
117119
write_overall_metrics_tables(
118120
issues_with_metrics,

test_markdown_writer.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import unittest
1111
from datetime import timedelta
12-
from unittest.mock import mock_open, patch
12+
from unittest.mock import call, mock_open, patch
1313

1414
from classes import IssueWithMetrics
1515
from markdown_writer import write_to_markdown
@@ -219,11 +219,19 @@ def test_write_to_markdown_no_issues(self):
219219
write_to_markdown(None, None, None, None, None, None, None)
220220

221221
# Check that the file was written correctly
222-
expected_output = "no issues found for the given search criteria\n\n"
223-
mock_open_file.assert_called_once_with(
224-
"issue_metrics.md", "w", encoding="utf-8"
222+
expected_output = [
223+
"# Issue Metrics\n\n",
224+
"no issues found for the given search criteria\n\n",
225+
"\n_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n",
226+
]
227+
# Check that the markdown file was written with the three calls in expected output
228+
mock_open_file.assert_has_calls(
229+
[
230+
call().write(expected_output[0]),
231+
call().write(expected_output[1]),
232+
call().write(expected_output[2]),
233+
]
225234
)
226-
mock_open_file().write.assert_called_once_with(expected_output)
227235

228236

229237
class TestWriteToMarkdownWithEnv(unittest.TestCase):

0 commit comments

Comments
 (0)