From 282b16ddb4bb8da044e55d549a5cf138b8f9f1f2 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Wed, 25 Oct 2023 15:27:08 -0700 Subject: [PATCH] always print the title and search query Signed-off-by: Zack Koppert --- markdown_writer.py | 18 ++++++++++-------- test_markdown_writer.py | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/markdown_writer.py b/markdown_writer.py index 052281a..889a525 100644 --- a/markdown_writer.py +++ b/markdown_writer.py @@ -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, diff --git a/test_markdown_writer.py b/test_markdown_writer.py index 1eac4b0..f741e66 100644 --- a/test_markdown_writer.py +++ b/test_markdown_writer.py @@ -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 @@ -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):