Skip to content

Commit d8f4956

Browse files
committed
fixes negative time to completion values
1 parent 04854e9 commit d8f4956

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

linear/client.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,40 @@
1111

1212
def _compute_assignee_time_to_fix(issue, assignee_name):
1313
"""Return days between last assignment to `assignee_name` and completion."""
14-
history = issue.get("history", {}).get("edges", [])
15-
last_assigned = None
16-
for edge in history:
17-
node = edge.get("node", {})
18-
to_assignee = node.get("toAssignee")
19-
if not to_assignee:
20-
continue
21-
if to_assignee.get("displayName") == assignee_name:
22-
updated = node.get("updatedAt")
23-
if updated and (last_assigned is None or updated > last_assigned):
24-
last_assigned = updated
25-
if not last_assigned:
26-
return None
2714
completed_at = issue.get("completedAt")
2815
if not completed_at:
2916
return None
3017
try:
3118
completed_dt = datetime.strptime(completed_at, "%Y-%m-%dT%H:%M:%S.%fZ")
32-
assigned_dt = datetime.strptime(last_assigned, "%Y-%m-%dT%H:%M:%S.%fZ")
33-
return (completed_dt - assigned_dt).days
3419
except ValueError:
3520
return None
3621

22+
history = issue.get("history", {}).get("edges", [])
23+
last_assigned = None
24+
for edge in history:
25+
node = edge.get("node", {})
26+
to_assignee = node.get("toAssignee")
27+
if not to_assignee or to_assignee.get("displayName") != assignee_name:
28+
continue
29+
updated = node.get("updatedAt")
30+
if not updated:
31+
continue
32+
try:
33+
updated_dt = datetime.strptime(updated, "%Y-%m-%dT%H:%M:%S.%fZ")
34+
except ValueError:
35+
continue
36+
if updated_dt > completed_dt:
37+
# Ignore assignment changes that happened after the issue was closed.
38+
continue
39+
if last_assigned is None or updated_dt > last_assigned:
40+
last_assigned = updated_dt
41+
42+
if last_assigned is None:
43+
return None
44+
45+
delta_days = (completed_dt - last_assigned).days
46+
return max(delta_days, 0)
47+
3748

3849
_thread_local = threading.local()
3950

0 commit comments

Comments
 (0)