Skip to content

Commit

Permalink
fix: more linting, 3 to go
Browse files Browse the repository at this point in the history
replace comments with variables, causes ensured maintenance of meaning

Signed-off-by: jmeridth <[email protected]>
  • Loading branch information
jmeridth committed Mar 24, 2024
1 parent be1272d commit eed2aaa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import json
import os
from datetime import timedelta
from typing import List, Union
from typing import Any, List, Union

from classes import IssueWithMetrics

Expand Down Expand Up @@ -114,7 +114,7 @@ def write_to_json(
p90_time_in_labels[label] = str(time)

# Create a dictionary with the metrics
metrics = {
metrics: dict[str, Any] = {
"average_time_to_first_response": str(average_time_to_first_response),
"average_time_to_close": str(average_time_to_close),
"average_time_to_answer": str(average_time_to_answer),
Expand Down
10 changes: 5 additions & 5 deletions labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:

def get_stats_time_in_labels(
issues_with_metrics: List[IssueWithMetrics],
labels: List[str],
) -> dict[str, timedelta]:
labels: dict[str, timedelta],
) -> dict[str, dict[str, timedelta | None ]]:
"""Calculate stats describing time spent in each label."""
time_in_labels = {}
for issue in issues_with_metrics:
Expand All @@ -107,9 +107,9 @@ def get_stats_time_in_labels(
issue.label_metrics[label].total_seconds()
)

average_time_in_labels = {}
med_time_in_labels = {}
ninety_percentile_in_labels = {}
average_time_in_labels: dict[str, timedelta | None] = {}
med_time_in_labels: dict[str, timedelta | None] = {}
ninety_percentile_in_labels: dict[str, timedelta | None] = {}
for label, time_list in time_in_labels.items():
average_time_in_labels[label] = timedelta(
seconds=numpy.round(numpy.average(time_list))
Expand Down
2 changes: 1 addition & 1 deletion test_time_to_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestGetAverageTimeToAnswer(unittest.TestCase):
def test_returns_none_for_empty_list(self):
"""Tests that the function returns None when given an empty list of issues."""
# Arrange
issues_with_metrics: List[IssueWithMetrics] = []
issues_with_metrics = []

# Act
result = get_stats_time_to_answer(issues_with_metrics)
Expand Down
30 changes: 18 additions & 12 deletions time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ def measure_time_to_first_response(
if ready_for_review_at:
issue_time = ready_for_review_at
else:
issue_time = datetime.fromisoformat(issue.created_at) # type: ignore
issue_time = datetime.fromisoformat(issue.created_at)

if discussion and len(discussion["comments"]["nodes"]) > 0:
earliest_response = datetime.fromisoformat(
discussion["comments"]["nodes"][0]["createdAt"]
)
issue_time = datetime.fromisoformat(discussion["createdAt"])

# Calculate the time between the issue and the first comment
if earliest_response and issue_time:
return earliest_response - issue_time
time_between_issue_and_first_comment: timedelta | None = (
earliest_response - issue_time
)
return time_between_issue_and_first_comment

return None

Expand All @@ -122,16 +124,20 @@ def ignore_comment(
ready_for_review_at: Union[datetime, None],
) -> bool:
"""Check if a comment should be ignored."""
return (
# ignore comments by IGNORE_USERS
comment_user.login in ignore_users
# ignore comments by bots
or comment_user.type == "Bot"
# ignore comments by the issue creator
or comment_user.login == issue_user.login
# ignore comments created before the issue was ready for review
or (ready_for_review_at and comment_created_at < ready_for_review_at)

user_is_ignored: bool = comment_user.login in ignore_users
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 = (
ready_for_review_at and (comment_created_at < ready_for_review_at)
)
result: bool = (
user_is_ignored
or user_is_a_bot
or user_is_issue_creator
or issue_was_created_before_ready_for_review
)
return result


def get_stats_time_to_first_response(
Expand Down

0 comments on commit eed2aaa

Please sign in to comment.