diff --git a/test_time_to_first_response.py b/test_time_to_first_response.py index a8d8b1c..58259c6 100644 --- a/test_time_to_first_response.py +++ b/test_time_to_first_response.py @@ -34,6 +34,7 @@ def test_measure_time_to_first_response(self): # Set up the mock GitHub issues 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 issue comments @@ -55,6 +56,7 @@ def test_measure_time_to_first_response_no_comments(self): # Set up mock issues with no comments mock_issue1 = MagicMock() mock_issue1.comments = 0 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" # Call the function @@ -70,6 +72,7 @@ def test_measure_time_to_first_response_with_pull_request_comments(self): # Set up the mock GitHub issues mock_issue1 = MagicMock() mock_issue1.comments = 2 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" mock_issue1.pull_request_urls = {"url": "https://api.github.com/repos/owner/repo/pulls/1"} @@ -93,6 +96,7 @@ def test_measure_time_to_first_response_issue_comment_faster(self): # Set up the mock GitHub issues mock_issue1 = MagicMock() mock_issue1.comments = 2 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" mock_issue1.pull_request_urls = {"url": "https://api.github.com/repos/owner/repo/pulls/1"} @@ -119,6 +123,7 @@ def test_measure_time_to_first_response_pull_request_comment_faster(self): # Set up the mock GitHub issues mock_issue1 = MagicMock() mock_issue1.comments = 2 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" mock_issue1.pull_request_urls = {"url": "https://api.github.com/repos/owner/repo/pulls/1"} @@ -144,6 +149,7 @@ def test_measure_time_to_first_response_ignore_users(self): # Set up the mock GitHub issues mock_issue1 = MagicMock() mock_issue1.comments = 4 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" # Set up the mock GitHub issue comments (one ignored, one not ignored) @@ -176,6 +182,7 @@ def test_measure_time_to_first_response_only_ignored_users(self): # Set up the mock GitHub issues mock_issue1 = MagicMock() mock_issue1.comments = 4 + mock_issue1.issue.user.login = "issue_owner" mock_issue1.created_at = "2023-01-01T00:00:00Z" mock_issue1.pull_request_urls = {"url": "https://api.github.com/repos/owner/repo/pulls/1"} @@ -206,6 +213,40 @@ def test_measure_time_to_first_response_only_ignored_users(self): # Check the results self.assertEqual(result, expected_result) + def test_measure_time_to_first_response_ignore_issue_owners_comment(self): + """Test that measure_time_to_first_response ignore issue owner's comment.""" + # Set up the mock GitHub issues + mock_issue1 = MagicMock() + mock_issue1.comments = 4 + mock_issue1.issue.user.login = "issue_owner" + mock_issue1.created_at = "2023-01-01T00:00:00Z" + mock_issue1.pull_request_urls = {"url": "https://api.github.com/repos/owner/repo/pulls/1"} + + # Set up the mock GitHub issue comments + mock_comment1 = MagicMock() + mock_comment1.user.login = "issue_owner" + mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z") + mock_comment2 = MagicMock() + mock_comment2.user.login = "other_user" + mock_comment2.created_at = datetime.fromisoformat("2023-01-05T00:00:00Z") + mock_issue1.issue.comments.return_value = [mock_comment1, mock_comment2] + + # Set up the mock GitHub pull request comments + mock_pr_comment1 = MagicMock() + mock_pr_comment1.user.login = "issue_owner" + mock_pr_comment1.submitted_at = datetime.fromisoformat("2023-01-03T00:00:00Z") + mock_pr_comment2 = MagicMock() + mock_pr_comment2.user.login = "other_user" + mock_pr_comment2.submitted_at = datetime.fromisoformat("2023-01-04T00:00:00Z") + mock_issue1.issue.pull_request().reviews.return_value = [mock_pr_comment1, mock_pr_comment2] + + # Call the function + result = measure_time_to_first_response(mock_issue1, None) + expected_result = timedelta(days=3) + + # Check the results + self.assertEqual(result, expected_result) + class TestGetAverageTimeToFirstResponse(unittest.TestCase): """Test the get_average_time_to_first_response function.""" diff --git a/time_to_first_response.py b/time_to_first_response.py index 5cf2532..6e4fef9 100644 --- a/time_to_first_response.py +++ b/time_to_first_response.py @@ -55,6 +55,8 @@ def measure_time_to_first_response( for comment in comments: if comment.user.login in ignore_users: continue + if comment.user.login == issue.issue.user.login: + continue first_comment_time = comment.created_at break @@ -66,6 +68,8 @@ def measure_time_to_first_response( for review_comment in review_comments: if review_comment.user.login in ignore_users: continue + if review_comment.user.login == issue.issue.user.login: + continue first_review_comment_time = review_comment.submitted_at break