github / issue-metrics

Gather metrics on issues/prs/discussions such as time to first response, count of issues opened, closed, etc.

Home Page:https://github.blog/2023-07-19-metrics-for-issues-pull-requests-and-discussions/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError when measuring time to first response

christopherlo93 opened this issue · comments

I was testing this with PRs in my org that were closed in the last two weeks:

Traceback (most recent call last):
  File "/action/workspace/issue_metrics.py", line 331, in <module>
    main()
  File "/action/workspace/issue_metrics.py", line 286, in main
    issues_with_metrics, num_issues_open, num_issues_closed = get_per_issue_metrics(
                                                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/issue_metrics.py", line 180, in get_per_issue_metrics
    issue_with_metrics.time_to_first_response = measure_time_to_first_response(
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/time_to_first_response.py", line 77, in measure_time_to_first_response
    if ignore_comment(
       ^^^^^^^^^^^^^^^
  File "/action/workspace/time_to_first_response.py", line 133, in ignore_comment
    or (ready_for_review_at and comment_created_at < ready_for_review_at)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'

I have a feeling it may be a draft PR that was closed before it was ever ready for review.

I think your feeling seems to be correct. In this GitHub Actions, it appears that the time spent in draft PRs is being excluded from the calculation.

Although I haven't confirmed it, closing a draft PR without making it ready for review might trigger this bug.

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 14 days.

Hey! New here to the repo but really enjoy it. Wanted to say thanks by trying to help out a bit.

or (ready_for_review_at and comment_created_at < ready_for_review_at)
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'

Looking at the error, ready_for_review_at exists and it'scomment_created_at that is None, causing it to break.

comment_created_at is defined as review_comment.submitted_at, which might not exist if a review is still in the PENDING state: https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request

I can try and tackle this. Would the correct behavior be to ignore reviews that are still in the pending state?

Correct, we would want to ignore pending reviews.

Fixed by #236