diff --git a/markdown_writer.py b/markdown_writer.py index 7a88a8a..67cc241 100644 --- a/markdown_writer.py +++ b/markdown_writer.py @@ -75,10 +75,6 @@ def get_non_hidden_columns(labels) -> List[str]: if not hide_time_to_answer: columns.append("Time to answer") - hide_status = env_vars.hide_status - if not hide_status: - columns.append("Status") - enable_time_in_draft = env_vars.draft_pr_tracking if enable_time_in_draft: columns.append("Time in draft") @@ -91,6 +87,10 @@ def get_non_hidden_columns(labels) -> List[str]: if not hide_created_at: columns.append("Created At") + hide_status = env_vars.hide_status + if not hide_status: + columns.append("Status") + return columns diff --git a/test_column_order_fix.py b/test_column_order_fix.py new file mode 100644 index 0000000..c186ad7 --- /dev/null +++ b/test_column_order_fix.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 + +""" +Test to verify that the Status and Created At columns have their content aligned with headers. + +This test specifically validates the fix for issue #568 where the Status and Created At +columns had their data swapped. +""" + +import os +import unittest +from datetime import timedelta +from unittest.mock import patch + +from classes import IssueWithMetrics +from markdown_writer import get_non_hidden_columns, write_to_markdown + + +@patch.dict( + os.environ, + { + "SEARCH_QUERY": "is:open repo:user/repo", + "GH_TOKEN": "test_token", + "HIDE_CREATED_AT": "False", + "HIDE_STATUS": "False", + }, +) +class TestColumnOrderFix(unittest.TestCase): + """Test that Status and Created At columns have correct data.""" + + def test_status_and_created_at_columns_alignment(self): + """Test that Status and Created At columns show correct data values. + + This test specifically validates that: + 1. The Status column contains actual status values (not dates) + 2. The Created At column contains actual date values (not status) + """ + # Create test data with clearly distinguishable Status and Created At values + issues_with_metrics = [ + IssueWithMetrics( + title="Test Issue", + html_url="https://github.com/user/repo/issues/1", + author="testuser", + assignee="assignee1", + assignees=["assignee1"], + created_at="2023-01-01T00:00:00Z", # This should appear in Created At column + status="open", # This should appear in Status column + time_to_first_response=timedelta(days=1), + time_to_close=timedelta(days=2), + time_to_answer=timedelta(days=3), + ) + ] + + # Call the function + write_to_markdown( + issues_with_metrics=issues_with_metrics, + average_time_to_first_response=None, + average_time_to_close=None, + average_time_to_answer=None, + average_time_in_draft=None, + average_time_in_labels=None, + num_issues_opened=1, + num_issues_closed=0, + num_mentor_count=0, + labels=None, + search_query="is:issue is:open repo:user/repo", + hide_label_metrics=True, + hide_items_closed_count=False, + enable_mentor_count=False, + non_mentioning_links=False, + report_title="Test Report", + output_file="test_column_order.md", + ) + + # Read the generated markdown + with open("test_column_order.md", "r", encoding="utf-8") as file: + content = file.read() + + # The table should have the columns in the correct order + # and the data should be properly aligned + expected_header = ( + "| Title | URL | Assignee | Author | Time to first response | " + "Time to close | Time to answer | Created At | Status |" + ) + self.assertIn(expected_header, content) + + # Verify the data row has correct values in correct positions + # The Created At column should contain the date value + # The Status column should contain the status value + expected_row = ( + "| Test Issue | https://github.com/user/repo/issues/1 | " + "[assignee1](https://github.com/assignee1) | " + "[testuser](https://github.com/testuser) | 1 day, 0:00:00 | " + "2 days, 0:00:00 | 3 days, 0:00:00 | 2023-01-01T00:00:00Z | open |" + ) + self.assertIn(expected_row, content) + + # Clean up + os.remove("test_column_order.md") + + def test_get_non_hidden_columns_order(self): + """Test that get_non_hidden_columns returns columns in the correct order.""" + columns = get_non_hidden_columns(labels=None) + + # Find the indices of the Status and Created At columns + try: + created_at_index = columns.index("Created At") + status_index = columns.index("Status") + + # Status should come after Created At + self.assertGreater( + status_index, + created_at_index, + "Status column should come after Created At column", + ) + except ValueError: + # If one of the columns is hidden, that's fine, but we shouldn't get here + # given our environment variables + self.fail("Both Status and Created At columns should be present") + + +if __name__ == "__main__": + unittest.main() diff --git a/test_markdown_writer.py b/test_markdown_writer.py index 0fbcad3..c79536b 100644 --- a/test_markdown_writer.py +++ b/test_markdown_writer.py @@ -137,7 +137,7 @@ def test_write_to_markdown(self): "| Number of items closed | 1 |\n" "| Total number of items created | 2 |\n\n" "| Title | URL | Assignee | Author | Time to first response | Time to close | " - "Time to answer | Status | Time in draft | Time spent in bug | Created At |\n" + "Time to answer | Time in draft | Time spent in bug | Created At | Status |\n" "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n" "| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | " "[alice](https://github.com/alice) | 1 day, 0:00:00 | 2 days, 0:00:00 | 3 days, 0:00:00 | " @@ -254,7 +254,7 @@ def test_write_to_markdown_with_vertical_bar_in_title(self): "| Number of items closed | 1 |\n" "| Total number of items created | 2 |\n\n" "| Title | URL | Assignee | Author | Time to first response | Time to close | " - "Time to answer | Status | Time in draft | Time spent in bug | Created At |\n" + "Time to answer | Time in draft | Time spent in bug | Created At | Status |\n" "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n" "| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | " "[alice](https://github.com/alice) | 1 day, 0:00:00 | 2 days, 0:00:00 | 3 days, 0:00:00 | " @@ -405,7 +405,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self): "| Number of items that remain open | 2 |\n" "| Number of most active mentors | 5 |\n" "| Total number of items created | 2 |\n\n" - "| Title | URL | Assignee | Author | Status | Created At |\n" + "| Title | URL | Assignee | Author | Created At | Status |\n" "| --- | --- | --- | --- | --- | --- |\n" "| Issue 1 | https://www.ghe.com/user/repo/issues/1 | [charlie](https://ghe.com/charlie) | " "[alice](https://ghe.com/alice) | -5 days, 0:00:00 | None |\n"