From 4f29f34d9d831fe224cbc6c8a0d711415ebd01b1 Mon Sep 17 00:00:00 2001 From: lawang24 Date: Sun, 14 Apr 2024 01:55:56 -0400 Subject: [PATCH] Handle Pending Review Case (#236) --- most_active_mentors.py | 2 ++ test_time_to_first_response.py | 30 ++++++++++++++++++++++++++++++ time_to_first_response.py | 4 +++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/most_active_mentors.py b/most_active_mentors.py index 99bdfae..be0483e 100755 --- a/most_active_mentors.py +++ b/most_active_mentors.py @@ -147,6 +147,8 @@ def ignore_comment( or comment_user.type == "Bot" # ignore comments by the issue creator or comment_user.login == issue_user.login + # ignore pending reviews + or not comment_created_at # ignore comments created before the issue was ready for review or (ready_for_review_at and comment_created_at < ready_for_review_at) ) diff --git a/test_time_to_first_response.py b/test_time_to_first_response.py index 437a0a9..a8e592a 100644 --- a/test_time_to_first_response.py +++ b/test_time_to_first_response.py @@ -233,6 +233,36 @@ def test_measure_time_to_first_response_ignore_users(self): # Check the results self.assertEqual(result, expected_result) + def test_measure_time_to_first_response_ignore_pending_review(self): + """Test that measure_time_to_first_response ignores pending reviews""" + + mock_issue1 = MagicMock() + mock_issue1.comments = 2 + mock_issue1.issue.user.login = "issue_owner" + mock_issue1.created_at = "2023-01-01T00:00:00Z" + + # Set up the mock GitHub pull request comments (one ignored, one not ignored) + # Pending Review + mock_pr_comment1 = MagicMock() + mock_pr_comment1.submitted_at = None + # Submitted Comment + mock_pr_comment2 = MagicMock() + mock_pr_comment2.submitted_at = datetime.fromisoformat("2023-01-04T00:00:00Z") + + mock_pull_request = MagicMock() + mock_pull_request.reviews.return_value = [mock_pr_comment1, mock_pr_comment2] + + ready_for_review_at = datetime.fromisoformat("2023-01-03T00:00:00Z") + + # Call the function + result = measure_time_to_first_response( + mock_issue1, None, mock_pull_request, ready_for_review_at + ) + expected_result = timedelta(days=1) + + # Check the results + self.assertEqual(result, expected_result) + def test_measure_time_to_first_response_only_ignored_users(self): """Test that measure_time_to_first_response returns empty for an issue with only ignored users.""" # Set up the mock GitHub issues diff --git a/time_to_first_response.py b/time_to_first_response.py index 46dc3b8..1f2dc1a 100644 --- a/time_to_first_response.py +++ b/time_to_first_response.py @@ -129,7 +129,8 @@ def ignore_comment( user_is_a_bot: bool = str(comment_user.type.lower()) == "bot" user_is_issue_creator: bool = str(comment_user.login) == str(issue_user.login) issue_was_created_before_ready_for_review: bool = False - if ready_for_review_at: + is_pending_comment: bool = not isinstance(comment_created_at, datetime) + if ready_for_review_at and not is_pending_comment: issue_was_created_before_ready_for_review = ( comment_created_at < ready_for_review_at ) @@ -137,6 +138,7 @@ def ignore_comment( user_is_ignored or user_is_a_bot or user_is_issue_creator + or is_pending_comment or issue_was_created_before_ready_for_review ) return result