Skip to content

Commit 65f43f4

Browse files
authored
fix: Status and Created At column header/data alignment issue (#569)
1 parent 2fd323a commit 65f43f4

File tree

3 files changed

+130
-7
lines changed

3 files changed

+130
-7
lines changed

markdown_writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ def get_non_hidden_columns(labels) -> List[str]:
7575
if not hide_time_to_answer:
7676
columns.append("Time to answer")
7777

78-
hide_status = env_vars.hide_status
79-
if not hide_status:
80-
columns.append("Status")
81-
8278
enable_time_in_draft = env_vars.draft_pr_tracking
8379
if enable_time_in_draft:
8480
columns.append("Time in draft")
@@ -91,6 +87,10 @@ def get_non_hidden_columns(labels) -> List[str]:
9187
if not hide_created_at:
9288
columns.append("Created At")
9389

90+
hide_status = env_vars.hide_status
91+
if not hide_status:
92+
columns.append("Status")
93+
9494
return columns
9595

9696

test_column_order_fix.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Test to verify that the Status and Created At columns have their content aligned with headers.
5+
6+
This test specifically validates the fix for issue #568 where the Status and Created At
7+
columns had their data swapped.
8+
"""
9+
10+
import os
11+
import unittest
12+
from datetime import timedelta
13+
from unittest.mock import patch
14+
15+
from classes import IssueWithMetrics
16+
from markdown_writer import get_non_hidden_columns, write_to_markdown
17+
18+
19+
@patch.dict(
20+
os.environ,
21+
{
22+
"SEARCH_QUERY": "is:open repo:user/repo",
23+
"GH_TOKEN": "test_token",
24+
"HIDE_CREATED_AT": "False",
25+
"HIDE_STATUS": "False",
26+
},
27+
)
28+
class TestColumnOrderFix(unittest.TestCase):
29+
"""Test that Status and Created At columns have correct data."""
30+
31+
def test_status_and_created_at_columns_alignment(self):
32+
"""Test that Status and Created At columns show correct data values.
33+
34+
This test specifically validates that:
35+
1. The Status column contains actual status values (not dates)
36+
2. The Created At column contains actual date values (not status)
37+
"""
38+
# Create test data with clearly distinguishable Status and Created At values
39+
issues_with_metrics = [
40+
IssueWithMetrics(
41+
title="Test Issue",
42+
html_url="https://github.com/user/repo/issues/1",
43+
author="testuser",
44+
assignee="assignee1",
45+
assignees=["assignee1"],
46+
created_at="2023-01-01T00:00:00Z", # This should appear in Created At column
47+
status="open", # This should appear in Status column
48+
time_to_first_response=timedelta(days=1),
49+
time_to_close=timedelta(days=2),
50+
time_to_answer=timedelta(days=3),
51+
)
52+
]
53+
54+
# Call the function
55+
write_to_markdown(
56+
issues_with_metrics=issues_with_metrics,
57+
average_time_to_first_response=None,
58+
average_time_to_close=None,
59+
average_time_to_answer=None,
60+
average_time_in_draft=None,
61+
average_time_in_labels=None,
62+
num_issues_opened=1,
63+
num_issues_closed=0,
64+
num_mentor_count=0,
65+
labels=None,
66+
search_query="is:issue is:open repo:user/repo",
67+
hide_label_metrics=True,
68+
hide_items_closed_count=False,
69+
enable_mentor_count=False,
70+
non_mentioning_links=False,
71+
report_title="Test Report",
72+
output_file="test_column_order.md",
73+
)
74+
75+
# Read the generated markdown
76+
with open("test_column_order.md", "r", encoding="utf-8") as file:
77+
content = file.read()
78+
79+
# The table should have the columns in the correct order
80+
# and the data should be properly aligned
81+
expected_header = (
82+
"| Title | URL | Assignee | Author | Time to first response | "
83+
"Time to close | Time to answer | Created At | Status |"
84+
)
85+
self.assertIn(expected_header, content)
86+
87+
# Verify the data row has correct values in correct positions
88+
# The Created At column should contain the date value
89+
# The Status column should contain the status value
90+
expected_row = (
91+
"| Test Issue | https://github.com/user/repo/issues/1 | "
92+
"[assignee1](https://github.com/assignee1) | "
93+
"[testuser](https://github.com/testuser) | 1 day, 0:00:00 | "
94+
"2 days, 0:00:00 | 3 days, 0:00:00 | 2023-01-01T00:00:00Z | open |"
95+
)
96+
self.assertIn(expected_row, content)
97+
98+
# Clean up
99+
os.remove("test_column_order.md")
100+
101+
def test_get_non_hidden_columns_order(self):
102+
"""Test that get_non_hidden_columns returns columns in the correct order."""
103+
columns = get_non_hidden_columns(labels=None)
104+
105+
# Find the indices of the Status and Created At columns
106+
try:
107+
created_at_index = columns.index("Created At")
108+
status_index = columns.index("Status")
109+
110+
# Status should come after Created At
111+
self.assertGreater(
112+
status_index,
113+
created_at_index,
114+
"Status column should come after Created At column",
115+
)
116+
except ValueError:
117+
# If one of the columns is hidden, that's fine, but we shouldn't get here
118+
# given our environment variables
119+
self.fail("Both Status and Created At columns should be present")
120+
121+
122+
if __name__ == "__main__":
123+
unittest.main()

test_markdown_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_write_to_markdown(self):
137137
"| Number of items closed | 1 |\n"
138138
"| Total number of items created | 2 |\n\n"
139139
"| Title | URL | Assignee | Author | Time to first response | Time to close | "
140-
"Time to answer | Status | Time in draft | Time spent in bug | Created At |\n"
140+
"Time to answer | Time in draft | Time spent in bug | Created At | Status |\n"
141141
"| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n"
142142
"| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
143143
"[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):
254254
"| Number of items closed | 1 |\n"
255255
"| Total number of items created | 2 |\n\n"
256256
"| Title | URL | Assignee | Author | Time to first response | Time to close | "
257-
"Time to answer | Status | Time in draft | Time spent in bug | Created At |\n"
257+
"Time to answer | Time in draft | Time spent in bug | Created At | Status |\n"
258258
"| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n"
259259
"| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
260260
"[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):
405405
"| Number of items that remain open | 2 |\n"
406406
"| Number of most active mentors | 5 |\n"
407407
"| Total number of items created | 2 |\n\n"
408-
"| Title | URL | Assignee | Author | Status | Created At |\n"
408+
"| Title | URL | Assignee | Author | Created At | Status |\n"
409409
"| --- | --- | --- | --- | --- | --- |\n"
410410
"| Issue 1 | https://www.ghe.com/user/repo/issues/1 | [charlie](https://ghe.com/charlie) | "
411411
"[alice](https://ghe.com/alice) | -5 days, 0:00:00 | None |\n"

0 commit comments

Comments
 (0)