Skip to content

Commit

Permalink
Handle Pending Review Case (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawang24 authored Apr 14, 2024
1 parent eb98ac5 commit 4f29f34
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions most_active_mentors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
30 changes: 30 additions & 0 deletions test_time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ 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
)
result: bool = (
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
Expand Down

0 comments on commit 4f29f34

Please sign in to comment.