Repository: github/issue-metrics
Pull request #157 (2023-10-25 22:28:28)

always print the title and search query
<!-- Please ensure your PR title is brief and descriptive for a good changelog entry -->
<!-- Link to issue if there is one -->
Related to https://github.com/github/issue-metrics/issues/156
<!-- Describe what the changes are -->

## Proposed Changes
- always printing the title and search query even when the results are empty

## Readiness Checklist

### Author/Contributor
- [x] If documentation is needed for this change, has that been included in this pull request
- [x] run `make lint` and fix any issues that you have introduced
- [x] run `make test` and ensure you have test coverage for the lines you are introducing

### Reviewer
- [x] Label as either `bug`, `documentation`, `enhancement`, `infrastructure`, or `breaking`



Patch:
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,


Test patch:
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 @@ Classes:
 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 @@ class TestWriteToMarkdown(unittest.TestCase):
             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):