@@ -101,25 +101,41 @@ def measure_time_to_first_response(
101
101
Union[timedelta, None]: The time to first response for the issue.
102
102
103
103
"""
104
- # Get the first comment
105
- if issue . comments <= 0 :
106
- return None
104
+ first_review_comment_time = None
105
+ first_comment_time = None
106
+ earliest_response = None
107
107
108
+ # Get the first comment time
108
109
comments = issue .issue .comments (
109
110
number = 1 , sort = "created" , direction = "asc"
110
111
) # type: ignore
111
-
112
- # Get the created_at time for the first comment
113
- first_comment_time = None
114
112
for comment in comments :
115
- first_comment_time = comment .created_at # type: ignore
113
+ first_comment_time = comment .created_at
114
+
115
+ # Check if the issue is actually a pull request
116
+ # so we may also get the first review comment time
117
+ if issue .issue .pull_request_urls :
118
+ pull_request = issue .issue .pull_request ()
119
+ review_comments = pull_request .reviews (number = 1 ) # type: ignore
120
+ for review_comment in review_comments :
121
+ first_review_comment_time = review_comment .submitted_at
122
+
123
+ # Figure out the earliest response timestamp
124
+ if first_comment_time and first_review_comment_time :
125
+ earliest_response = min (first_comment_time , first_review_comment_time )
126
+ elif first_comment_time :
127
+ earliest_response = first_comment_time
128
+ elif first_review_comment_time :
129
+ earliest_response = first_review_comment_time
130
+ else :
131
+ return None
116
132
117
- # Get the created_at time for the issue
133
+ # Get the created_at time for the issue so we can calculate the time to first response
118
134
issue_time = datetime .fromisoformat (issue .created_at ) # type: ignore
119
135
120
136
# Calculate the time between the issue and the first comment
121
- if first_comment_time and issue_time :
122
- return first_comment_time - issue_time
137
+ if earliest_response and issue_time :
138
+ return earliest_response - issue_time
123
139
124
140
return None
125
141
0 commit comments