|
11 | 11 |
|
12 | 12 | def _compute_assignee_time_to_fix(issue, assignee_name): |
13 | 13 | """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 |
27 | 14 | completed_at = issue.get("completedAt") |
28 | 15 | if not completed_at: |
29 | 16 | return None |
30 | 17 | try: |
31 | 18 | 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 |
34 | 19 | except ValueError: |
35 | 20 | return None |
36 | 21 |
|
| 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 | + |
37 | 48 |
|
38 | 49 | _thread_local = threading.local() |
39 | 50 |
|
|
0 commit comments