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

fix: count reviews as responses #30

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
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
36 changes: 26 additions & 10 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,41 @@ def measure_time_to_first_response(
Union[timedelta, None]: The time to first response for the issue.

"""
# Get the first comment
if issue.comments <= 0:
return None
first_review_comment_time = None
first_comment_time = None
earliest_response = None

# Get the first comment time
comments = issue.issue.comments(
number=1, sort="created", direction="asc"
) # type: ignore

# Get the created_at time for the first comment
first_comment_time = None
for comment in comments:
first_comment_time = comment.created_at # type: ignore
first_comment_time = comment.created_at

# Check if the issue is actually a pull request
# so we may also get the first review comment time
if issue.issue.pull_request_urls:
pull_request = issue.issue.pull_request()
review_comments = pull_request.reviews(number=1) # type: ignore
for review_comment in review_comments:
first_review_comment_time = review_comment.submitted_at

# Figure out the earliest response timestamp
if first_comment_time and first_review_comment_time:
earliest_response = min(first_comment_time, first_review_comment_time)
elif first_comment_time:
earliest_response = first_comment_time
elif first_review_comment_time:
earliest_response = first_review_comment_time
else:
return None

# Get the created_at time for the issue
# Get the created_at time for the issue so we can calculate the time to first response
issue_time = datetime.fromisoformat(issue.created_at) # type: ignore

# Calculate the time between the issue and the first comment
if first_comment_time and issue_time:
return first_comment_time - issue_time
if earliest_response and issue_time:
return earliest_response - issue_time

return None

Expand Down