Skip to content

Commit f7dfd0f

Browse files
Copilotzkoppert
andcommitted
Address code review feedback: improve type annotations and remove side effects
Co-authored-by: zkoppert <[email protected]>
1 parent 6861148 commit f7dfd0f

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

json_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import json
2222
import os
2323
from datetime import timedelta
24-
from typing import Any, List, Union
24+
from typing import Any, Dict, List, Union
2525

2626
from classes import IssueWithMetrics
2727

@@ -33,7 +33,7 @@ def write_to_json(
3333
stats_time_to_answer: Union[dict[str, timedelta], None],
3434
stats_time_in_draft: Union[dict[str, timedelta], None],
3535
stats_time_in_labels: Union[dict[str, dict[str, timedelta]], None],
36-
stats_pr_comments: Union[dict[str, float], None],
36+
stats_pr_comments: Union[Dict[str, float], None],
3737
num_issues_opened: Union[int, None],
3838
num_issues_closed: Union[int, None],
3939
num_mentor_count: Union[int, None],

markdown_writer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def write_to_markdown(
151151
152152
"""
153153
columns = get_non_hidden_columns(labels)
154+
env_vars = get_env_vars()
154155
output_file_name = output_file if output_file else "issue_metrics.md"
155156
with open(output_file_name, "w", encoding="utf-8") as file:
156157
file.write(f"# {report_title}\n\n")
@@ -184,6 +185,7 @@ def write_to_markdown(
184185
hide_label_metrics,
185186
hide_items_closed_count,
186187
enable_mentor_count,
188+
env_vars.hide_pr_statistics,
187189
)
188190

189191
# Write second table with individual issue/pr/discussion metrics
@@ -274,9 +276,9 @@ def write_overall_metrics_tables(
274276
hide_label_metrics,
275277
hide_items_closed_count=False,
276278
enable_mentor_count=False,
279+
hide_pr_statistics=True,
277280
):
278281
"""Write the overall metrics tables to the markdown file."""
279-
env_vars = get_env_vars()
280282

281283
if (
282284
any(
@@ -289,7 +291,7 @@ def write_overall_metrics_tables(
289291
]
290292
)
291293
or (hide_label_metrics is False and len(labels) > 0)
292-
or (not env_vars.hide_pr_statistics and stats_pr_comments is not None)
294+
or (not hide_pr_statistics and stats_pr_comments is not None)
293295
):
294296
file.write("| Metric | Average | Median | 90th percentile |\n")
295297
file.write("| --- | --- | --- | ---: |\n")
@@ -347,7 +349,7 @@ def write_overall_metrics_tables(
347349
)
348350

349351
# Add PR comment statistics if not hidden
350-
if not env_vars.hide_pr_statistics and stats_pr_comments is not None:
352+
if not hide_pr_statistics and stats_pr_comments is not None:
351353
file.write(
352354
f"| Number of comments per PR "
353355
f"| {stats_pr_comments['avg']} "

pr_comments.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,4 @@ def get_stats_pr_comments(
112112
"90p": ninety_percentile_comment_count,
113113
}
114114

115-
# Print the statistics
116-
print(f"Average number of comments per PR: {average_comment_count}")
117-
print(f"Median number of comments per PR: {median_comment_count}")
118-
print(f"90th percentile of comments per PR: {ninety_percentile_comment_count}")
119-
120115
return stats

test_pr_comments.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import unittest
8-
from datetime import timedelta
98
from unittest.mock import MagicMock
109

1110
from classes import IssueWithMetrics
@@ -92,7 +91,9 @@ def test_count_pr_comments_exception_handling(self):
9291
mock_issue.issue.comments.side_effect = AttributeError("No comments")
9392

9493
mock_pull_request = MagicMock()
95-
mock_pull_request.review_comments.side_effect = AttributeError("No review comments")
94+
mock_pull_request.review_comments.side_effect = AttributeError(
95+
"No review comments"
96+
)
9697

9798
result = count_pr_comments(mock_issue, mock_pull_request, [])
9899
self.assertEqual(result, 0)
@@ -134,4 +135,4 @@ def test_get_stats_pr_comments_empty_list(self):
134135

135136

136137
if __name__ == "__main__":
137-
unittest.main()
138+
unittest.main()

0 commit comments

Comments
 (0)