-
Notifications
You must be signed in to change notification settings - Fork 55
/
time_to_ready_for_review.py
51 lines (40 loc) · 1.45 KB
/
time_to_ready_for_review.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""A module for getting the time a pull request was marked as ready for review
after being in draft mode.
This module provides functions for getting the time a GitHub pull request was
marked as ready for review, if it was formerly in draft mode.
Functions:
get_time_to_ready_for_review(
issue: github3.issues.Issue,
pull_request: github3.pulls.PullRequest
) -> Union[datetime, None]:
If a pull request was formerly a draft, get the time it was marked as
ready for review.
"""
from datetime import datetime
from typing import Union
import github3
def get_time_to_ready_for_review(
issue: github3.issues.Issue,
pull_request: github3.pulls.PullRequest,
) -> Union[datetime, None]:
"""If a pull request was formerly a draft, get the time it was marked as ready
for review
Args:
issue (github3.issues.Issue): A GitHub issue.
pull_request (github3.pulls.PullRequest): A GitHub pull request.
Returns:
Union[datetime, None]: The time the pull request was marked as ready for review
"""
if pull_request.draft:
return None
events = issue.issue.events(number=50)
try:
for event in events:
if event.event == "ready_for_review":
return event.created_at
except TypeError as e:
print(
f"An error occurred processing review events. Perhaps issue contains a ghost user. {e}"
)
return None
return None