Skip to content

Commit

Permalink
fix: linting fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Apr 2, 2024
1 parent 1a01093 commit ddb16e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
20 changes: 15 additions & 5 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions most_active_mentors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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/
Expand All @@ -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
Expand Down
26 changes: 18 additions & 8 deletions test_most_active_mentors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_mentor_count function.
"""

import unittest
from datetime import datetime
from unittest.mock import MagicMock
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ddb16e2

Please sign in to comment.