Skip to content
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

always print the title and search query #157

Merged
merged 1 commit into from
Oct 27, 2023
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
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