diff --git a/issue_metrics.py b/issue_metrics.py index f3d28a0..8cd9834 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -126,7 +126,7 @@ def get_per_issue_metrics( labels: Union[List[str], None] = None, ignore_users: Union[List[str], None] = None, max_comments_to_eval: int = 20, - heavily_involved: int = 3 + heavily_involved: int = 3, ) -> tuple[List, int, int]: """ Calculate the metrics for each issue/pr/discussion in a list provided. @@ -165,8 +165,13 @@ def get_per_issue_metrics( None, issue, ignore_users ) issue_with_metrics.mentor_activity = count_comments_per_user( - None, issue, ignore_users, None, None, - max_comments_to_eval, heavily_involved + None, + issue, + ignore_users, + None, + None, + max_comments_to_eval, + heavily_involved, ) issue_with_metrics.time_to_answer = measure_time_to_answer(issue) if issue["closedAt"]: @@ -195,8 +200,13 @@ def get_per_issue_metrics( issue, None, pull_request, ready_for_review_at, ignore_users ) issue_with_metrics.mentor_activity = count_comments_per_user( - issue, None, pull_request, ready_for_review_at, ignore_users, - max_comments_to_eval, heavily_involved + issue, + None, + pull_request, + ready_for_review_at, + ignore_users, + max_comments_to_eval, + heavily_involved, ) if labels: issue_with_metrics.label_metrics = get_label_metrics(issue, labels) diff --git a/most_active_mentors.py b/most_active_mentors.py index 5b9acd0..99bdfae 100755 --- a/most_active_mentors.py +++ b/most_active_mentors.py @@ -33,9 +33,10 @@ Count the number of mentors active at least n times """ + from collections import Counter from datetime import datetime -from typing import List, Union +from typing import Dict, List, Union import github3 from classes import IssueWithMetrics @@ -46,7 +47,7 @@ def count_comments_per_user( discussion: Union[dict, None] = None, pull_request: Union[github3.pulls.PullRequest, None] = None, ready_for_review_at: Union[datetime, None] = None, - ignore_users: List[str] = None, + ignore_users: List[str] | None = None, max_comments_to_eval=20, heavily_involved=3, ) -> dict: @@ -67,7 +68,7 @@ def count_comments_per_user( """ if ignore_users is None: ignore_users = [] - mentor_count = {} + mentor_count: Dict[str, int] = {} # Get the first comments if issue: @@ -118,7 +119,7 @@ def count_comments_per_user( comment.user, ignore_users, comment.submitted_at, - comment.ready_for_review_at + comment.ready_for_review_at, ): continue @@ -139,7 +140,7 @@ def ignore_comment( ready_for_review_at: Union[datetime, None], ) -> bool: """Check if a comment should be ignored.""" - return ( + return bool( # ignore comments by IGNORE_USERS comment_user.login in ignore_users # ignore comments by bots @@ -151,11 +152,8 @@ def ignore_comment( ) -def get_mentor_count( - issues_with_metrics: List[IssueWithMetrics], - cutoff: int -) -> int: - """ Calculate the number of active mentors on the project. +def get_mentor_count(issues_with_metrics: List[IssueWithMetrics], cutoff: int) -> int: + """Calculate the number of active mentors on the project. Args: issues_with_metrics (List[IssueWithMetrics]): A list of issues w/ @@ -168,7 +166,7 @@ def get_mentor_count( """ - mentor_count = Counter({}) + mentor_count: Counter[str] = Counter({}) for issue_with_metrics in issues_with_metrics: current_counter = Counter(issue_with_metrics.mentor_activity) mentor_count = mentor_count + current_counter diff --git a/test_most_active_mentors.py b/test_most_active_mentors.py index 7c5defd..15edb95 100755 --- a/test_most_active_mentors.py +++ b/test_most_active_mentors.py @@ -10,6 +10,7 @@ get_mentor_count function. """ + import unittest from datetime import datetime from unittest.mock import MagicMock @@ -40,7 +41,10 @@ def test_count_comments_per_user(self): for i in range(22): mock_comment1 = MagicMock() mock_comment1.user.login = "very_active_user" - mock_comment1.created_at = datetime.fromisoformat(f"2023-01-02T{i:02d}:00:00Z") + mock_comment1.created_at = datetime.fromisoformat( + f"2023-01-02T{i:02d}:00:00Z" + ) + # pylint: disable=maybe-no-member mock_issue1.issue.comments.return_value.append(mock_comment1) # Call the function @@ -51,19 +55,25 @@ def test_count_comments_per_user(self): self.assertEqual(result, expected_result) def test_get_mentor_count(self): - """ Test that get_mentor_count correctly counts comments per user. - - """ + """Test that get_mentor_count correctly counts comments per user.""" mentor_activity = {"sue": 15, "bob": 10} # Create moc data issues_with_metrics = [ IssueWithMetrics( - "Issue 1", "https://github.com/user/repo/issues/1", - "alice", None, mentor_activity=mentor_activity), + "Issue 1", + "https://github.com/user/repo/issues/1", + "alice", + None, + mentor_activity=mentor_activity, + ), IssueWithMetrics( - "Issue 2", "https://github.com/user/repo/issues/2", - "bob", None, mentor_activity=mentor_activity), + "Issue 2", + "https://github.com/user/repo/issues/2", + "bob", + None, + mentor_activity=mentor_activity, + ), ] # Call the function and check the result