-
Notifications
You must be signed in to change notification settings - Fork 57
/
time_to_merge.py
44 lines (31 loc) · 1.3 KB
/
time_to_merge.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
"""A module for measuring the time it takes to merge a GitHub pull request.
This module provides functions for measuring the time it takes to merge a GitHub pull
request, as well as calculating the average time to merge for a list of pull requests.
Functions:
measure_time_to_merge(
pull_request: github3.pulls.PullRequest,
ready_for_review_at: Union[datetime, None]
) -> Union[timedelta, None]:
Measure the time it takes to merge a pull request.
"""
from datetime import datetime, timedelta
from typing import Union
import github3
def measure_time_to_merge(
pull_request: github3.pulls.PullRequest, ready_for_review_at: Union[datetime, None]
) -> Union[timedelta, None]:
"""Measure the time it takes to merge a pull request.
Args:
pull_request (github3.pulls.PullRequest): A GitHub pull request.
ready_for_review_at (Union[timedelta, None]): When the PR was marked as ready for review
Returns:
Union[datetime.timedelta, None]: The time it takes to close the issue.
"""
merged_at = None
if pull_request.merged_at is None:
return None
merged_at = pull_request.merged_at
if ready_for_review_at:
return merged_at - ready_for_review_at
created_at = pull_request.created_at
return merged_at - created_at