Skip to content

Commit 4f29f34

Browse files
authored
Handle Pending Review Case (#236)
1 parent eb98ac5 commit 4f29f34

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

most_active_mentors.py

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def ignore_comment(
147147
or comment_user.type == "Bot"
148148
# ignore comments by the issue creator
149149
or comment_user.login == issue_user.login
150+
# ignore pending reviews
151+
or not comment_created_at
150152
# ignore comments created before the issue was ready for review
151153
or (ready_for_review_at and comment_created_at < ready_for_review_at)
152154
)

test_time_to_first_response.py

+30
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ def test_measure_time_to_first_response_ignore_users(self):
233233
# Check the results
234234
self.assertEqual(result, expected_result)
235235

236+
def test_measure_time_to_first_response_ignore_pending_review(self):
237+
"""Test that measure_time_to_first_response ignores pending reviews"""
238+
239+
mock_issue1 = MagicMock()
240+
mock_issue1.comments = 2
241+
mock_issue1.issue.user.login = "issue_owner"
242+
mock_issue1.created_at = "2023-01-01T00:00:00Z"
243+
244+
# Set up the mock GitHub pull request comments (one ignored, one not ignored)
245+
# Pending Review
246+
mock_pr_comment1 = MagicMock()
247+
mock_pr_comment1.submitted_at = None
248+
# Submitted Comment
249+
mock_pr_comment2 = MagicMock()
250+
mock_pr_comment2.submitted_at = datetime.fromisoformat("2023-01-04T00:00:00Z")
251+
252+
mock_pull_request = MagicMock()
253+
mock_pull_request.reviews.return_value = [mock_pr_comment1, mock_pr_comment2]
254+
255+
ready_for_review_at = datetime.fromisoformat("2023-01-03T00:00:00Z")
256+
257+
# Call the function
258+
result = measure_time_to_first_response(
259+
mock_issue1, None, mock_pull_request, ready_for_review_at
260+
)
261+
expected_result = timedelta(days=1)
262+
263+
# Check the results
264+
self.assertEqual(result, expected_result)
265+
236266
def test_measure_time_to_first_response_only_ignored_users(self):
237267
"""Test that measure_time_to_first_response returns empty for an issue with only ignored users."""
238268
# Set up the mock GitHub issues

time_to_first_response.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,16 @@ def ignore_comment(
129129
user_is_a_bot: bool = str(comment_user.type.lower()) == "bot"
130130
user_is_issue_creator: bool = str(comment_user.login) == str(issue_user.login)
131131
issue_was_created_before_ready_for_review: bool = False
132-
if ready_for_review_at:
132+
is_pending_comment: bool = not isinstance(comment_created_at, datetime)
133+
if ready_for_review_at and not is_pending_comment:
133134
issue_was_created_before_ready_for_review = (
134135
comment_created_at < ready_for_review_at
135136
)
136137
result: bool = (
137138
user_is_ignored
138139
or user_is_a_bot
139140
or user_is_issue_creator
141+
or is_pending_comment
140142
or issue_was_created_before_ready_for_review
141143
)
142144
return result

0 commit comments

Comments
 (0)