Skip to content

Commit

Permalink
feature: exclude issue owner's comment
Browse files Browse the repository at this point in the history
Ignore issue comments and pr comments made by the issue owner.
  • Loading branch information
eichisanden committed Aug 17, 2023
1 parent 5f6055c commit 1aa4b78
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test_time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"}

Expand All @@ -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"}

Expand All @@ -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"}

Expand All @@ -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)
Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 1aa4b78

Please sign in to comment.