MCPcopy Create free account
hub / github.com/tirth8205/code-review-graph / _resolve_target

Function _resolve_target

code_review_graph/visualization.py:65–99  ·  view source on GitHub ↗

Try to resolve an unqualified edge target to a full qualified name. Returns the resolved qualified name, or None if unresolvable.

(
    target: str,
    source: str,
    seen_qn: set[str],
    name_index: dict[str, list[str]],
)

Source from the content-addressed store, hash-verified

63
64
65def _resolve_target(
66 target: str,
67 source: str,
68 seen_qn: set[str],
69 name_index: dict[str, list[str]],
70) -> str | None:
71 """Try to resolve an unqualified edge target to a full qualified name.
72
73 Returns the resolved qualified name, or None if unresolvable.
74 """
75 # Already fully qualified
76 if target in seen_qn:
77 return target
78
79 candidates = name_index.get(target)
80 if not candidates:
81 return None
82
83 if len(candidates) == 1:
84 return candidates[0]
85
86 # Disambiguate: prefer node in the same file as the source
87 src_file = source.split("::")[0] if "::" in source else source
88 same_file = [c for c in candidates if c.startswith(src_file)]
89 if len(same_file) == 1:
90 return same_file[0]
91
92 # Prefer node in the same top-level directory
93 src_parts = src_file.rsplit("/", 1)[0] if "/" in src_file else ""
94 same_dir = [c for c in candidates if c.startswith(src_parts)]
95 if len(same_dir) == 1:
96 return same_dir[0]
97
98 # Ambiguous — pick first match rather than dropping the edge
99 return candidates[0]
100
101
102def export_graph_data(store: GraphStore) -> dict:

Callers 1

export_graph_dataFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected