Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Comment on lines -78 to +81
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function auth_to_github refactored with the following changes:

github_connection = github3.login(token=token)
else:
raise ValueError("GH_TOKEN environment variable not set")
Expand All @@ -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
Comment on lines -100 to +102
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function measure_time_to_first_response refactored with the following changes:

else:
comments = issue.issue.comments(
number=1, sort="created", direction="asc"
Expand All @@ -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):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function measure_time_to_close refactored with the following changes:



def get_average_time_to_first_response(issues):
Expand Down Expand Up @@ -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(),
Comment on lines -252 to +251
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_average_time_to_close refactored with the following changes:

)

# Calculate the average time to close
Expand Down Expand Up @@ -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
Comment on lines -316 to 319
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

  • Simplify conditional into switch-like form (switch)

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(
Expand All @@ -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
Comment on lines -351 to -354
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_env_vars refactored with the following changes:



class IssueWithMetrics:
Expand Down