@@ -43,6 +43,7 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
43
43
"""
44
44
label_metrics : dict = {}
45
45
label_events = get_label_events (issue , labels )
46
+ label_last_event_type : dict = {}
46
47
47
48
for label in labels :
48
49
label_metrics [label ] = None
@@ -56,7 +57,9 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
56
57
# Calculate the time to add or subtract to the time spent in label based on the label events
57
58
for event in label_events :
58
59
# Skip labeling events that have occured past issue close time
59
- if issue .closed_at is not None and (event .created_at >= datetime .fromisoformat (issue .closed_at )):
60
+ if issue .closed_at is not None and (
61
+ event .created_at >= datetime .fromisoformat (issue .closed_at )
62
+ ):
60
63
continue
61
64
62
65
if event .event == "labeled" :
@@ -67,6 +70,7 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
67
70
label_metrics [
68
71
event .label ["name" ]
69
72
] -= event .created_at - datetime .fromisoformat (issue .created_at )
73
+ label_last_event_type [event .label ["name" ]] = "labeled"
70
74
elif event .event == "unlabeled" :
71
75
unlabeled [event .label ["name" ]] = True
72
76
if event .label ["name" ] in labels :
@@ -75,16 +79,20 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
75
79
label_metrics [
76
80
event .label ["name" ]
77
81
] += event .created_at - datetime .fromisoformat (issue .created_at )
82
+ label_last_event_type [event .label ["name" ]] = "unlabeled"
78
83
79
84
for label in labels :
80
- # if the label is still on there, add the time from the last event to now
81
85
if label in labeled :
82
86
# if the issue is closed, add the time from the issue creation to the closed_at time
83
87
if issue .state == "closed" :
84
88
label_metrics [label ] += datetime .fromisoformat (
85
89
issue .closed_at
86
90
) - datetime .fromisoformat (issue .created_at )
87
91
else :
92
+ # skip label if last labeling event is 'unlabled' and issue is still open
93
+ if label_last_event_type [label ] == "unlabeled" :
94
+ continue
95
+
88
96
# if the issue is open, add the time from the issue creation to now
89
97
label_metrics [label ] += datetime .now (pytz .utc ) - datetime .fromisoformat (
90
98
issue .created_at
0 commit comments