adre-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adre/__init__.py +5 -0
- adre/analyzers/__init__.py +1 -0
- adre/analyzers/architecture.py +253 -0
- adre/analyzers/findings.py +457 -0
- adre/analyzers/inference.py +163 -0
- adre/cli.py +923 -0
- adre/core/__init__.py +1 -0
- adre/core/accepted.py +225 -0
- adre/core/adaptive.py +221 -0
- adre/core/baseline.py +1165 -0
- adre/core/config.py +60 -0
- adre/core/decision_engine.py +361 -0
- adre/core/declared.py +313 -0
- adre/core/evolution_intelligence.py +390 -0
- adre/core/explainer.py +413 -0
- adre/core/git_intelligence.py +392 -0
- adre/core/github_check.py +212 -0
- adre/core/incremental.py +288 -0
- adre/core/layers.py +306 -0
- adre/core/pr_intelligence.py +261 -0
- adre/core/pr_review.py +454 -0
- adre/core/prioritization.py +196 -0
- adre/core/project.py +41 -0
- adre/core/refactor_intelligence.py +201 -0
- adre/core/repositories.py +312 -0
- adre/core/review.py +96 -0
- adre/core/rules_shared.py +75 -0
- adre/core/sarif.py +141 -0
- adre/core/scope.py +141 -0
- adre/core/snapshots.py +242 -0
- adre/core/stability_intelligence.py +361 -0
- adre/graph/__init__.py +0 -0
- adre/graph/dependencies.py +379 -0
- adre/parsers/__init__.py +87 -0
- adre/parsers/go.py +140 -0
- adre/parsers/javascript.py +364 -0
- adre/parsers/jvm.py +127 -0
- adre/parsers/python.py +153 -0
- adre/reports/__init__.py +1 -0
- adre/reports/architecture.py +349 -0
- adre/rules.py +12 -0
- adre/web.py +3731 -0
- adre_cli-0.1.0.dist-info/METADATA +343 -0
- adre_cli-0.1.0.dist-info/RECORD +48 -0
- adre_cli-0.1.0.dist-info/WHEEL +5 -0
- adre_cli-0.1.0.dist-info/entry_points.txt +2 -0
- adre_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
- adre_cli-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""Legacy snapshot-score PR comparison.
|
|
2
|
+
|
|
3
|
+
The CI and CLI path is core.pr_review.review_pull_request, which compares
|
|
4
|
+
the current checkout against ArchitectureBaseline. This module is kept for
|
|
5
|
+
older snapshot-based reports and is not used by GitHub checks.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import tempfile
|
|
10
|
+
|
|
11
|
+
from adre.analyzers.architecture import analyze_project_architecture
|
|
12
|
+
from adre.core.git_intelligence import get_repo_root, run_git, run_git_command
|
|
13
|
+
from adre.core.rules_shared import classify_architecture_change, recommendation_from_risk
|
|
14
|
+
from adre.core.snapshots import compare_snapshot_data, snapshot_from_analysis
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_changed_files(base_branch, head_branch, repo_path):
|
|
18
|
+
output = run_git(repo_path, ["diff", "--name-only", base_branch, head_branch])
|
|
19
|
+
return sorted(line.strip() for line in output.splitlines() if line.strip())
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def checkout_and_analyze(repo_root, ref, relative_project_path, temp_root, label):
|
|
23
|
+
safe_ref = ref.replace("/", "_").replace(":", "_")
|
|
24
|
+
clone_path = os.path.join(temp_root, f"{label}-{safe_ref}")
|
|
25
|
+
run_git_command(None, ["clone", "--quiet", "--no-checkout", "--template=", repo_root, clone_path])
|
|
26
|
+
run_git_command(clone_path, ["checkout", "--quiet", "--detach", ref])
|
|
27
|
+
analysis_path = os.path.join(clone_path, relative_project_path) if relative_project_path else clone_path
|
|
28
|
+
return analyze_project_architecture(analysis_path)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def normalize_changed_files(changed_files, relative_project_path):
|
|
32
|
+
if not relative_project_path:
|
|
33
|
+
return set(changed_files)
|
|
34
|
+
|
|
35
|
+
prefix = relative_project_path.rstrip(os.sep).replace(os.sep, "/") + "/"
|
|
36
|
+
normalized = set()
|
|
37
|
+
|
|
38
|
+
for file in changed_files:
|
|
39
|
+
if file == relative_project_path:
|
|
40
|
+
normalized.add(os.path.basename(file))
|
|
41
|
+
elif file.startswith(prefix):
|
|
42
|
+
normalized.add(file[len(prefix):])
|
|
43
|
+
|
|
44
|
+
return normalized
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def item_touches_changed_file(item, changed_files):
|
|
48
|
+
if not changed_files:
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
file_value = item.get("file")
|
|
52
|
+
imported_value = item.get("imported")
|
|
53
|
+
source_value = item.get("source")
|
|
54
|
+
target_value = item.get("target")
|
|
55
|
+
|
|
56
|
+
return any(
|
|
57
|
+
value in changed_files
|
|
58
|
+
for value in [file_value, imported_value, source_value, target_value]
|
|
59
|
+
if value
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def cycle_touches_changed_file(cycle, changed_files):
|
|
64
|
+
return any(file in changed_files for file in cycle)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def filter_pr_comparison(comparison, changed_files):
|
|
68
|
+
filtered = dict(comparison)
|
|
69
|
+
filtered["new_cycles"] = [
|
|
70
|
+
cycle for cycle in comparison.get("new_cycles", [])
|
|
71
|
+
if cycle_touches_changed_file(cycle, changed_files)
|
|
72
|
+
]
|
|
73
|
+
filtered["new_cycles_introduced"] = filtered["new_cycles"]
|
|
74
|
+
filtered["resolved_cycles"] = [
|
|
75
|
+
cycle for cycle in comparison.get("resolved_cycles", [])
|
|
76
|
+
if cycle_touches_changed_file(cycle, changed_files)
|
|
77
|
+
]
|
|
78
|
+
filtered["new_issues_introduced"] = [
|
|
79
|
+
issue for issue in comparison.get("new_issues_introduced", [])
|
|
80
|
+
if item_touches_changed_file(issue, changed_files)
|
|
81
|
+
]
|
|
82
|
+
filtered["issues_fixed"] = [
|
|
83
|
+
issue for issue in comparison.get("issues_fixed", [])
|
|
84
|
+
if item_touches_changed_file(issue, changed_files)
|
|
85
|
+
]
|
|
86
|
+
filtered["added_dependencies"] = [
|
|
87
|
+
edge for edge in comparison.get("added_dependencies", [])
|
|
88
|
+
if item_touches_changed_file(edge, changed_files)
|
|
89
|
+
]
|
|
90
|
+
filtered["removed_dependencies"] = [
|
|
91
|
+
edge for edge in comparison.get("removed_dependencies", [])
|
|
92
|
+
if item_touches_changed_file(edge, changed_files)
|
|
93
|
+
]
|
|
94
|
+
filtered["dependency_growth_per_file"] = [
|
|
95
|
+
growth for growth in comparison.get("dependency_growth_per_file", [])
|
|
96
|
+
if growth.get("file") in changed_files
|
|
97
|
+
]
|
|
98
|
+
return filtered
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def risk_level_from_pr(new_cycles, score_delta, hotspot_growth, layer_violation_delta):
|
|
102
|
+
return classify_architecture_change(
|
|
103
|
+
score_delta=score_delta,
|
|
104
|
+
new_cycle_count=len(new_cycles),
|
|
105
|
+
layer_violation_delta=layer_violation_delta,
|
|
106
|
+
hotspot_growth=hotspot_growth,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def summarize_responsible_files(pr_comparison):
|
|
111
|
+
files = set()
|
|
112
|
+
|
|
113
|
+
for issue in pr_comparison.get("new_issues_introduced", []):
|
|
114
|
+
if issue.get("file"):
|
|
115
|
+
files.add(issue["file"])
|
|
116
|
+
|
|
117
|
+
for cycle in pr_comparison.get("new_cycles", []):
|
|
118
|
+
files.update(cycle)
|
|
119
|
+
|
|
120
|
+
for edge in pr_comparison.get("added_dependencies", []):
|
|
121
|
+
if edge.get("source"):
|
|
122
|
+
files.add(edge["source"])
|
|
123
|
+
|
|
124
|
+
for growth in pr_comparison.get("dependency_growth_per_file", []):
|
|
125
|
+
if growth.get("file") and growth.get("net_dependency_delta", 0) > 0:
|
|
126
|
+
files.add(growth["file"])
|
|
127
|
+
|
|
128
|
+
return sorted(files)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def analyze_pr_diff(base_branch, head_branch, repo_path="."):
|
|
132
|
+
repo_path = os.path.realpath(os.path.abspath(repo_path))
|
|
133
|
+
repo_root = get_repo_root(repo_path)
|
|
134
|
+
relative_project_path = os.path.relpath(repo_path, repo_root)
|
|
135
|
+
|
|
136
|
+
if relative_project_path == ".":
|
|
137
|
+
relative_project_path = ""
|
|
138
|
+
|
|
139
|
+
changed_files = get_changed_files(base_branch, head_branch, repo_root)
|
|
140
|
+
changed_project_files = normalize_changed_files(changed_files, relative_project_path)
|
|
141
|
+
temp_root = tempfile.mkdtemp(prefix="adre-pr-")
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
baseline_analysis = checkout_and_analyze(repo_root, base_branch, relative_project_path, temp_root, "base")
|
|
145
|
+
head_analysis = checkout_and_analyze(repo_root, head_branch, relative_project_path, temp_root, "head")
|
|
146
|
+
finally:
|
|
147
|
+
shutil.rmtree(temp_root, ignore_errors=True)
|
|
148
|
+
|
|
149
|
+
baseline_snapshot = snapshot_from_analysis(baseline_analysis, name=base_branch)
|
|
150
|
+
head_snapshot = snapshot_from_analysis(head_analysis, name=head_branch)
|
|
151
|
+
comparison = compare_snapshot_data(baseline_snapshot, head_snapshot)
|
|
152
|
+
pr_comparison = filter_pr_comparison(comparison, changed_project_files)
|
|
153
|
+
hotspot_growth = sum(
|
|
154
|
+
max(0, growth.get("inbound_dependency_delta", 0))
|
|
155
|
+
for growth in pr_comparison.get("dependency_growth_per_file", [])
|
|
156
|
+
)
|
|
157
|
+
layer_violation_delta = (
|
|
158
|
+
len(pr_comparison.get("new_issues_introduced", []))
|
|
159
|
+
- len(pr_comparison.get("issues_fixed", []))
|
|
160
|
+
)
|
|
161
|
+
score_delta = head_analysis["score"] - baseline_analysis["score"]
|
|
162
|
+
risk_level = risk_level_from_pr(
|
|
163
|
+
pr_comparison.get("new_cycles", []),
|
|
164
|
+
score_delta,
|
|
165
|
+
hotspot_growth,
|
|
166
|
+
layer_violation_delta,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
"base_branch": base_branch,
|
|
171
|
+
"head_branch": head_branch,
|
|
172
|
+
"changed_files": changed_files,
|
|
173
|
+
"changed_project_files": sorted(changed_project_files),
|
|
174
|
+
"pr_score": head_analysis["score"],
|
|
175
|
+
"baseline_score": baseline_analysis["score"],
|
|
176
|
+
"score_delta": score_delta,
|
|
177
|
+
"new_cycles": pr_comparison.get("new_cycles", []),
|
|
178
|
+
"resolved_cycles": pr_comparison.get("resolved_cycles", []),
|
|
179
|
+
"new_layer_violations": pr_comparison.get("new_issues_introduced", []),
|
|
180
|
+
"removed_violations": pr_comparison.get("issues_fixed", []),
|
|
181
|
+
"hotspot_growth": hotspot_growth,
|
|
182
|
+
"added_dependencies": pr_comparison.get("added_dependencies", []),
|
|
183
|
+
"removed_dependencies": pr_comparison.get("removed_dependencies", []),
|
|
184
|
+
"dependency_growth_per_file": pr_comparison.get("dependency_growth_per_file", []),
|
|
185
|
+
"responsible_files": summarize_responsible_files(pr_comparison),
|
|
186
|
+
"risk_level": risk_level,
|
|
187
|
+
"recommendation": recommendation_from_risk(risk_level),
|
|
188
|
+
"comparison": pr_comparison,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def detect_pr_architecture_regression(pr_analysis):
|
|
193
|
+
reasons = []
|
|
194
|
+
violation_delta = (
|
|
195
|
+
len(pr_analysis.get("new_layer_violations", []))
|
|
196
|
+
- len(pr_analysis.get("removed_violations", []))
|
|
197
|
+
)
|
|
198
|
+
severity = classify_architecture_change(
|
|
199
|
+
score_delta=pr_analysis.get("score_delta", 0),
|
|
200
|
+
new_cycle_count=len(pr_analysis.get("new_cycles", [])),
|
|
201
|
+
layer_violation_delta=violation_delta,
|
|
202
|
+
hotspot_growth=pr_analysis.get("hotspot_growth", 0),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if pr_analysis.get("new_cycles"):
|
|
206
|
+
reasons.append(f"{len(pr_analysis['new_cycles'])} new cycle(s) introduced")
|
|
207
|
+
|
|
208
|
+
if pr_analysis.get("score_delta", 0) < -10:
|
|
209
|
+
reasons.append(f"architecture score dropped by {abs(pr_analysis['score_delta'])}")
|
|
210
|
+
|
|
211
|
+
if pr_analysis.get("hotspot_growth", 0) >= 3:
|
|
212
|
+
reasons.append(f"hotspot inbound dependency pressure increased by {pr_analysis['hotspot_growth']}")
|
|
213
|
+
|
|
214
|
+
if violation_delta > 0:
|
|
215
|
+
reasons.append(f"{violation_delta} net new layer violation(s)")
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
"regression_detected": bool(reasons),
|
|
219
|
+
"severity": severity,
|
|
220
|
+
"reasons": reasons,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def generate_pr_architecture_summary(pr_analysis):
|
|
225
|
+
regression = detect_pr_architecture_regression(pr_analysis)
|
|
226
|
+
recommendation = pr_analysis.get("recommendation", "allow")
|
|
227
|
+
verdict = {
|
|
228
|
+
"allow": "Safe to merge",
|
|
229
|
+
"warn": "Review suggested before merge",
|
|
230
|
+
"block": "Block merge until architecture regression is fixed",
|
|
231
|
+
}.get(recommendation, "Review suggested before merge")
|
|
232
|
+
|
|
233
|
+
suggested_fixes = []
|
|
234
|
+
|
|
235
|
+
for cycle in pr_analysis.get("new_cycles", []):
|
|
236
|
+
suggested_fixes.append("Break cycle: " + " -> ".join(cycle))
|
|
237
|
+
|
|
238
|
+
for issue in pr_analysis.get("new_layer_violations", []):
|
|
239
|
+
suggested_fixes.append(
|
|
240
|
+
f"Route {issue.get('file')} dependency on {issue.get('imported')} through an allowed architecture boundary."
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
for growth in pr_analysis.get("dependency_growth_per_file", []):
|
|
244
|
+
if growth.get("net_dependency_delta", 0) > 0:
|
|
245
|
+
suggested_fixes.append(
|
|
246
|
+
f"Reduce coupling pressure in {growth.get('file')} by narrowing imports or extracting a facade."
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
"architecture_score_change": {
|
|
251
|
+
"baseline_score": pr_analysis.get("baseline_score"),
|
|
252
|
+
"pr_score": pr_analysis.get("pr_score"),
|
|
253
|
+
"score_delta": pr_analysis.get("score_delta"),
|
|
254
|
+
},
|
|
255
|
+
"key_risks_introduced": regression["reasons"],
|
|
256
|
+
"files_responsible_for_risk": pr_analysis.get("responsible_files", []),
|
|
257
|
+
"suggested_fixes": suggested_fixes[:10],
|
|
258
|
+
"merge_safety_verdict": verdict,
|
|
259
|
+
"recommendation": recommendation,
|
|
260
|
+
"risk_level": pr_analysis.get("risk_level"),
|
|
261
|
+
}
|