Find flows that include nodes from the given changed files. Returns:: { "affected_flows": [ ], "total": , }
(
store: GraphStore,
changed_files: list[str],
)
| 656 | |
| 657 | |
| 658 | def get_affected_flows( |
| 659 | store: GraphStore, |
| 660 | changed_files: list[str], |
| 661 | ) -> dict: |
| 662 | """Find flows that include nodes from the given changed files. |
| 663 | |
| 664 | Returns:: |
| 665 | |
| 666 | { |
| 667 | "affected_flows": [<flow dicts>], |
| 668 | "total": <int>, |
| 669 | } |
| 670 | """ |
| 671 | if not changed_files: |
| 672 | return {"affected_flows": [], "total": 0} |
| 673 | |
| 674 | # Find node IDs belonging to changed files. |
| 675 | node_ids = store.get_node_ids_by_files(changed_files) |
| 676 | |
| 677 | if not node_ids: |
| 678 | return {"affected_flows": [], "total": 0} |
| 679 | |
| 680 | # Find flow IDs that contain any of these nodes. |
| 681 | flow_ids = store.get_flow_ids_by_node_ids(node_ids) |
| 682 | |
| 683 | if not flow_ids: |
| 684 | return {"affected_flows": [], "total": 0} |
| 685 | |
| 686 | affected: list[dict] = [] |
| 687 | for fid in flow_ids: |
| 688 | flow = get_flow_by_id(store, fid) |
| 689 | if flow: |
| 690 | affected.append(flow) |
| 691 | |
| 692 | # Sort by criticality descending. |
| 693 | affected.sort(key=lambda f: f.get("criticality", 0), reverse=True) |
| 694 | |
| 695 | return { |
| 696 | "affected_flows": affected, |
| 697 | "total": len(affected), |
| 698 | } |