Skip to content

Commit 2d023ab

Browse files
committed
Skip processing label time if last event is unlabled and issue is open
1 parent 16c00d0 commit 2d023ab

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

labels.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
4343
"""
4444
label_metrics: dict = {}
4545
label_events = get_label_events(issue, labels)
46+
label_last_event_type: dict = {}
4647

4748
for label in labels:
4849
label_metrics[label] = None
@@ -56,7 +57,9 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
5657
# Calculate the time to add or subtract to the time spent in label based on the label events
5758
for event in label_events:
5859
# 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+
):
6063
continue
6164

6265
if event.event == "labeled":
@@ -67,6 +70,7 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
6770
label_metrics[
6871
event.label["name"]
6972
] -= event.created_at - datetime.fromisoformat(issue.created_at)
73+
label_last_event_type[event.label["name"]] = "labeled"
7074
elif event.event == "unlabeled":
7175
unlabeled[event.label["name"]] = True
7276
if event.label["name"] in labels:
@@ -75,16 +79,20 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
7579
label_metrics[
7680
event.label["name"]
7781
] += event.created_at - datetime.fromisoformat(issue.created_at)
82+
label_last_event_type[event.label["name"]] = "unlabeled"
7883

7984
for label in labels:
80-
# if the label is still on there, add the time from the last event to now
8185
if label in labeled:
8286
# if the issue is closed, add the time from the issue creation to the closed_at time
8387
if issue.state == "closed":
8488
label_metrics[label] += datetime.fromisoformat(
8589
issue.closed_at
8690
) - datetime.fromisoformat(issue.created_at)
8791
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+
8896
# if the issue is open, add the time from the issue creation to now
8997
label_metrics[label] += datetime.now(pytz.utc) - datetime.fromisoformat(
9098
issue.created_at

0 commit comments

Comments
 (0)