Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Pending Review Case #236

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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