Skip to content

Commit 035687d

Browse files
Copilotzkoppert
andcommitted
Clean up code formatting and add integration tests
Co-authored-by: zkoppert <[email protected]>
1 parent be2f85c commit 035687d

File tree

3 files changed

+166
-5
lines changed

3 files changed

+166
-5
lines changed

issue_metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ def get_per_issue_metrics(
126126
issue_dict = issue.issue.as_dict() # type: ignore
127127
assignee = None
128128
assignees = []
129-
129+
130130
if issue_dict.get("assignee"):
131131
assignee = issue_dict["assignee"]["login"]
132-
132+
133133
if issue_dict.get("assignees"):
134134
assignees = [a["login"] for a in issue_dict["assignees"]]
135-
135+
136136
issue_with_metrics.assignee = assignee
137137
issue_with_metrics.assignees = assignees
138138

markdown_writer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,16 @@ def write_to_markdown(
209209
file.write(f"| {issue.title} | {issue.html_url} |")
210210
if "Assignee" in columns:
211211
if issue.assignee:
212-
file.write(f" [{issue.assignee}](https://{endpoint}/{issue.assignee}) |")
212+
file.write(
213+
f" [{issue.assignee}](https://{endpoint}/"
214+
f"{issue.assignee}) |"
215+
)
213216
else:
214217
file.write(" None |")
215218
if "Author" in columns:
216-
file.write(f" [{issue.author}](https://{endpoint}/{issue.author}) |")
219+
file.write(
220+
f" [{issue.author}](https://{endpoint}/{issue.author}) |"
221+
)
217222
if "Time to first response" in columns:
218223
file.write(f" {issue.time_to_first_response} |")
219224
if "Time to close" in columns:

test_assignee_integration.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""Integration test for assignee functionality."""
2+
3+
import json
4+
import os
5+
import tempfile
6+
import unittest
7+
from unittest.mock import MagicMock, patch
8+
from datetime import datetime, timedelta
9+
from classes import IssueWithMetrics
10+
from markdown_writer import write_to_markdown
11+
from json_writer import write_to_json
12+
13+
14+
class TestAssigneeIntegration(unittest.TestCase):
15+
"""Integration test for assignee functionality."""
16+
17+
@patch.dict(
18+
os.environ,
19+
{
20+
"GH_TOKEN": "test_token",
21+
"SEARCH_QUERY": "repo:test/repo is:issue",
22+
},
23+
clear=True,
24+
)
25+
def test_assignee_in_markdown_output(self):
26+
"""Test that assignee information appears correctly in markdown output."""
27+
issues_with_metrics = [
28+
IssueWithMetrics(
29+
title="Test Issue 1",
30+
html_url="https://github.com/test/repo/issues/1",
31+
author="john",
32+
assignee="alice",
33+
assignees=["alice"],
34+
time_to_first_response=timedelta(hours=2),
35+
time_to_close=timedelta(days=1),
36+
created_at=datetime.now() - timedelta(days=2),
37+
),
38+
IssueWithMetrics(
39+
title="Test Issue 2",
40+
html_url="https://github.com/test/repo/issues/2",
41+
author="jane",
42+
assignee=None,
43+
assignees=[],
44+
time_to_first_response=timedelta(hours=4),
45+
time_to_close=None,
46+
created_at=datetime.now() - timedelta(days=1),
47+
),
48+
]
49+
50+
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as f:
51+
output_file = f.name
52+
53+
try:
54+
write_to_markdown(
55+
issues_with_metrics=issues_with_metrics,
56+
average_time_to_first_response={"avg": timedelta(hours=3), "med": timedelta(hours=3), "90p": timedelta(hours=4)},
57+
average_time_to_close={"avg": timedelta(days=1), "med": timedelta(days=1), "90p": timedelta(days=1)},
58+
average_time_to_answer=None,
59+
average_time_in_draft=None,
60+
average_time_in_labels=None,
61+
num_issues_opened=2,
62+
num_issues_closed=1,
63+
num_mentor_count=0,
64+
labels=None,
65+
search_query="repo:test/repo is:issue",
66+
hide_label_metrics=True,
67+
hide_items_closed_count=False,
68+
enable_mentor_count=False,
69+
non_mentioning_links=False,
70+
report_title="Test Issue Metrics",
71+
output_file=output_file,
72+
ghe="",
73+
)
74+
75+
# Read and verify the markdown content
76+
with open(output_file, 'r') as f:
77+
content = f.read()
78+
79+
# Check for assignee column header
80+
self.assertIn("| Assignee |", content)
81+
82+
# Check for assignee data - alice should be linked
83+
self.assertIn("[alice](https://github.com/alice)", content)
84+
85+
# Check for None assignee
86+
self.assertIn("| None |", content)
87+
88+
# Check that both assignee and author columns are present
89+
self.assertIn("| Author |", content)
90+
91+
finally:
92+
os.unlink(output_file)
93+
94+
def test_assignee_in_json_output(self):
95+
"""Test that assignee information appears correctly in JSON output."""
96+
issues_with_metrics = [
97+
IssueWithMetrics(
98+
title="Test Issue 1",
99+
html_url="https://github.com/test/repo/issues/1",
100+
author="john",
101+
assignee="alice",
102+
assignees=["alice", "bob"],
103+
time_to_first_response=timedelta(hours=2),
104+
time_to_close=timedelta(days=1),
105+
created_at=datetime.now() - timedelta(days=2),
106+
),
107+
IssueWithMetrics(
108+
title="Test Issue 2",
109+
html_url="https://github.com/test/repo/issues/2",
110+
author="jane",
111+
assignee=None,
112+
assignees=[],
113+
time_to_first_response=timedelta(hours=4),
114+
time_to_close=None,
115+
created_at=datetime.now() - timedelta(days=1),
116+
),
117+
]
118+
119+
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
120+
output_file = f.name
121+
122+
try:
123+
json_output = write_to_json(
124+
issues_with_metrics=issues_with_metrics,
125+
stats_time_to_first_response={"avg": timedelta(hours=3), "med": timedelta(hours=3), "90p": timedelta(hours=4)},
126+
stats_time_to_close={"avg": timedelta(days=1), "med": timedelta(days=1), "90p": timedelta(days=1)},
127+
stats_time_to_answer=None,
128+
stats_time_in_draft=None,
129+
stats_time_in_labels=None,
130+
num_issues_opened=2,
131+
num_issues_closed=1,
132+
num_mentor_count=0,
133+
search_query="repo:test/repo is:issue",
134+
output_file=output_file,
135+
)
136+
137+
# Parse the JSON output
138+
data = json.loads(json_output)
139+
140+
# Check that assignee fields are present
141+
issue1 = data["issues"][0]
142+
self.assertEqual(issue1["assignee"], "alice")
143+
self.assertEqual(issue1["assignees"], ["alice", "bob"])
144+
self.assertEqual(issue1["author"], "john")
145+
146+
issue2 = data["issues"][1]
147+
self.assertIsNone(issue2["assignee"])
148+
self.assertEqual(issue2["assignees"], [])
149+
self.assertEqual(issue2["author"], "jane")
150+
151+
finally:
152+
os.unlink(output_file)
153+
154+
155+
if __name__ == "__main__":
156+
unittest.main()

0 commit comments

Comments
 (0)