-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
-100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
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(), | ||
Comment on lines
-252
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
) | ||
|
||
# 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 | ||
Comment on lines
-316
to
319
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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 | ||
Comment on lines
-351
to
-354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class IssueWithMetrics: | ||
|
There was a problem hiding this comment.
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:use-named-expression
)