From 5c3279dbf1737ef72b973e99b4aee33ca1f5b998 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 13 Jun 2023 16:11:02 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- issue_metrics.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/issue_metrics.py b/issue_metrics.py index cd0be6c..f7ade7a 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -61,8 +61,7 @@ def search_issues(repository_url, search_query, github_connection): def auth_to_github(): """Connect to GitHub.com or GitHub Enterprise, depending on env variables.""" - token = os.getenv("GH_TOKEN") - if token: + if token := os.getenv("GH_TOKEN"): github_connection = github3.login(token=token) else: raise ValueError("GH_TOKEN environment variable not set") @@ -83,7 +82,7 @@ def measure_time_to_first_response(issue): # Get the first comment if issue.comments <= 0: first_comment_time = None - time_to_first_response = None + return None else: comments = issue.issue.comments( number=1, sort="created", direction="asc" @@ -96,9 +95,7 @@ def measure_time_to_first_response(issue): issue_time = datetime.fromisoformat(issue.created_at) # type: ignore # Calculate the time between the issue and the first comment - time_to_first_response = first_comment_time - issue_time # type: ignore - - return time_to_first_response + return first_comment_time - issue_time def measure_time_to_close(issue): @@ -117,9 +114,7 @@ def measure_time_to_close(issue): closed_at = datetime.fromisoformat(issue.closed_at) created_at = datetime.fromisoformat(issue.created_at) - time_to_close = closed_at - created_at - - return time_to_close + return closed_at - created_at def get_average_time_to_first_response(issues): @@ -235,7 +230,8 @@ def get_average_time_to_close(issues_with_metrics): # Calculate the total time to close for all issues total_time_to_close = sum( - [issue.time_to_close for issue in issues_with_time_to_close], timedelta() + (issue.time_to_close for issue in issues_with_time_to_close), + timedelta(), ) # Calculate the average time to close @@ -299,10 +295,10 @@ def main(): ) if issue.state == "closed": # type: ignore issue_with_metrics.time_to_close = measure_time_to_close(issue) # type: ignore - if issue.state == "open": # type: ignore - num_issues_open += 1 - if issue.state == "closed": # type: ignore + if issue.state == "closed": num_issues_closed += 1 + elif issue.state == "open": + num_issues_open += 1 issues_with_metrics.append(issue_with_metrics) average_time_to_first_response = get_average_time_to_first_response( @@ -328,10 +324,10 @@ def get_env_vars(): if not search_query: raise ValueError("SEARCH_QUERY environment variable not set") - repo_url = os.getenv("REPOSITORY_URL") - if not repo_url: + if repo_url := os.getenv("REPOSITORY_URL"): + return search_query, repo_url + else: raise ValueError("REPOSITORY_URL environment variable not set") - return search_query, repo_url class IssueWithMetrics: