intentumdiff-python 0.0.1__py3-none-manylinux_2_39_x86_64.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.
- intentumdiff/__init__.py +134 -0
- intentumdiff/_differ_gate.py +210 -0
- intentumdiff/_differ_presentation.py +786 -0
- intentumdiff/_differ_runtime.py +320 -0
- intentumdiff/analysis/__init__.py +1 -0
- intentumdiff/analysis/compile_commands.py +151 -0
- intentumdiff/analysis/cross_file.py +71 -0
- intentumdiff/analysis/diagnostics.py +309 -0
- intentumdiff/analysis/guardrail_reports.py +254 -0
- intentumdiff/analysis/guardrails.py +318 -0
- intentumdiff/analysis/invariances.py +1207 -0
- intentumdiff/analysis/keyed_profiles.py +25 -0
- intentumdiff/analysis/resource_profiles.py +14 -0
- intentumdiff/analysis/schema_resolver.py +816 -0
- intentumdiff/analysis/text_review.py +46 -0
- intentumdiff/analysis/user_schemas.py +430 -0
- intentumdiff/assets.py +45 -0
- intentumdiff/cache/__init__.py +37 -0
- intentumdiff/cache/duckdb_store.py +98 -0
- intentumdiff/cache/sqlite_store.py +149 -0
- intentumdiff/cache/store.py +190 -0
- intentumdiff/cli/__init__.py +199 -0
- intentumdiff/cli/_commands.py +2141 -0
- intentumdiff/cli/_parser.py +1061 -0
- intentumdiff/cli/_shared.py +644 -0
- intentumdiff/content_type.py +59 -0
- intentumdiff/core/__init__.py +1 -0
- intentumdiff/core/commit_differ.py +599 -0
- intentumdiff/core/config.py +51 -0
- intentumdiff/core/cst_serializer.py +101 -0
- intentumdiff/core/diffignore.py +87 -0
- intentumdiff/core/index.py +189 -0
- intentumdiff/core/indexer.py +792 -0
- intentumdiff/core/models.py +837 -0
- intentumdiff/differ.py +2195 -0
- intentumdiff/github_app.py +287 -0
- intentumdiff/intentumdiff_rust_core/__init__.py +7 -0
- intentumdiff/intentumdiff_rust_core/ffi.py +8 -0
- intentumdiff/intentumdiff_rust_core/libintentumdiff_rust_core.so +0 -0
- intentumdiff/invariances/__init__.py +2 -0
- intentumdiff/invariances/rules.schema.json +283 -0
- intentumdiff/invariances/rules.yaml +349 -0
- intentumdiff/live_server.py +1314 -0
- intentumdiff/lsp/__init__.py +67 -0
- intentumdiff/lsp/client.py +544 -0
- intentumdiff/lsp/config.py +96 -0
- intentumdiff/lsp/enricher.py +227 -0
- intentumdiff/lsp/exceptions.py +27 -0
- intentumdiff/lsp/launcher.py +273 -0
- intentumdiff/lsp/servers.py +356 -0
- intentumdiff/lsp_server/__init__.py +14 -0
- intentumdiff/lsp_server/_codelens.py +67 -0
- intentumdiff/lsp_server/_diagnostics.py +62 -0
- intentumdiff/lsp_server/_handlers.py +175 -0
- intentumdiff/lsp_server/server.py +205 -0
- intentumdiff/plugins/__init__.py +1 -0
- intentumdiff/plugins/adapter.py +397 -0
- intentumdiff/plugins/builtins.py +323 -0
- intentumdiff/plugins/exceptions.py +93 -0
- intentumdiff/plugins/hub.py +1155 -0
- intentumdiff/plugins/language_metadata.py +250 -0
- intentumdiff/plugins/loader.py +1252 -0
- intentumdiff/plugins/registry.py +1079 -0
- intentumdiff/plugins/registry.schema.json +99 -0
- intentumdiff/plugins/registry_schema.py +280 -0
- intentumdiff/plugins/wit/plugin.wit +351 -0
- intentumdiff/rust_core.py +2370 -0
- intentumdiff/serve/__init__.py +19 -0
- intentumdiff/serve/_app.py +485 -0
- intentumdiff/serve/_static/index.html +326 -0
- intentumdiff/serve/_static/playground.js +567 -0
- intentumdiff/sources/__init__.py +1 -0
- intentumdiff/sources/base.py +28 -0
- intentumdiff/sources/file_source.py +48 -0
- intentumdiff/sources/git_source.py +375 -0
- intentumdiff/sources/live_buffer_source.py +113 -0
- intentumdiff/sources/patch_source.py +126 -0
- intentumdiff/sources/string_source.py +44 -0
- intentumdiff/testing.py +165 -0
- intentumdiff/vcs/__init__.py +37 -0
- intentumdiff/vcs/_safe_path.py +50 -0
- intentumdiff/vcs/base.py +136 -0
- intentumdiff/vcs/git_backend.py +97 -0
- intentumdiff/vcs/git_cli.py +100 -0
- intentumdiff/vcs/hg_backend.py +94 -0
- intentumdiff/vcs/perforce_backend.py +109 -0
- intentumdiff/vcs/svn_backend.py +105 -0
- intentumdiff/wasm/.gitkeep +2 -0
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/clojure_parser.wasm +0 -0
- intentumdiff/wasm/cmake_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/css_parser.wasm +0 -0
- intentumdiff/wasm/dart_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/delphi_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/elixir_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/go_parser.wasm +0 -0
- intentumdiff/wasm/gomod_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/haskell_parser.wasm +0 -0
- intentumdiff/wasm/html_parser.wasm +0 -0
- intentumdiff/wasm/ini_parser.wasm +0 -0
- intentumdiff/wasm/java_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/lua_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/markdown_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/parser_manifest.json +590 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/po_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/proto_parser.wasm +0 -0
- intentumdiff/wasm/puppet_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/r_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/ruby_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/scala_parser.wasm +0 -0
- intentumdiff/wasm/scss_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/squirrel_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/terraform_parser.wasm +0 -0
- intentumdiff/wasm/toml_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/xml_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/wasm/zig_parser.wasm +0 -0
- intentumdiff/watcher.py +259 -0
- intentumdiff_python-0.0.1.dist-info/METADATA +112 -0
- intentumdiff_python-0.0.1.dist-info/RECORD +165 -0
- intentumdiff_python-0.0.1.dist-info/WHEEL +4 -0
- intentumdiff_python-0.0.1.dist-info/entry_points.txt +80 -0
- intentumdiff_python-0.0.1.dist-info/licenses/LICENSE +21 -0
- intentumdiff_python-0.0.1.dist-info/sboms/intentumdiff-rust-core.cyclonedx.json +10968 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"""Repo-hostable GitHub App helpers for IntentumDiff review checks."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import html
|
|
6
|
+
import json
|
|
7
|
+
import urllib.parse
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, Mapping
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GitHubAppError(ValueError):
|
|
13
|
+
"""Raised when GitHub App input cannot be safely accepted."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class PullRequestRef:
|
|
18
|
+
owner: str
|
|
19
|
+
repo: str
|
|
20
|
+
number: int
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class GistRef:
|
|
25
|
+
gist_id: str
|
|
26
|
+
revision: str | None = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class GitHubAppReviewResult:
|
|
31
|
+
checked_files: int
|
|
32
|
+
semantic_changes: int
|
|
33
|
+
guardrail_violations: int
|
|
34
|
+
passed: bool
|
|
35
|
+
summary_markdown: str
|
|
36
|
+
html_report: str
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def verify_webhook_signature(secret: str, body: bytes, signature_header: str | None) -> bool:
|
|
40
|
+
"""Return True when *signature_header* matches GitHub's sha256 HMAC."""
|
|
41
|
+
|
|
42
|
+
if not secret or not signature_header or not signature_header.startswith("sha256="):
|
|
43
|
+
return False
|
|
44
|
+
expected = "sha256=" + hmac.new(secret.encode("utf-8"), body, hashlib.sha256).hexdigest()
|
|
45
|
+
return hmac.compare_digest(expected, signature_header)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_pull_request_url(url: str) -> PullRequestRef:
|
|
49
|
+
parsed = urllib.parse.urlparse(url)
|
|
50
|
+
if parsed.scheme != "https" or parsed.netloc.lower() != "github.com":
|
|
51
|
+
raise GitHubAppError("Pull request URL must use https://github.com")
|
|
52
|
+
parts = [part for part in parsed.path.split("/") if part]
|
|
53
|
+
if len(parts) != 4 or parts[2] != "pull":
|
|
54
|
+
raise GitHubAppError("Pull request URL must look like https://github.com/OWNER/REPO/pull/NUMBER")
|
|
55
|
+
try:
|
|
56
|
+
number = int(parts[3])
|
|
57
|
+
except ValueError as exc:
|
|
58
|
+
raise GitHubAppError("Pull request number must be an integer") from exc
|
|
59
|
+
if number <= 0:
|
|
60
|
+
raise GitHubAppError("Pull request number must be positive")
|
|
61
|
+
return PullRequestRef(owner=parts[0], repo=parts[1], number=number)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def parse_gist_url(url: str) -> GistRef:
|
|
65
|
+
parsed = urllib.parse.urlparse(url)
|
|
66
|
+
if parsed.scheme != "https" or parsed.netloc.lower() != "gist.github.com":
|
|
67
|
+
raise GitHubAppError("Gist URL must use https://gist.github.com")
|
|
68
|
+
parts = [part for part in parsed.path.split("/") if part]
|
|
69
|
+
if len(parts) not in {1, 2}:
|
|
70
|
+
raise GitHubAppError("Gist URL must look like https://gist.github.com/OWNER/GIST_ID")
|
|
71
|
+
gist_id = parts[-1]
|
|
72
|
+
if not gist_id or any(char in gist_id for char in "\\?#"):
|
|
73
|
+
raise GitHubAppError("Gist URL has an invalid gist id")
|
|
74
|
+
revision = None
|
|
75
|
+
fragment = parsed.fragment.strip()
|
|
76
|
+
if fragment.startswith("file-"):
|
|
77
|
+
revision = fragment
|
|
78
|
+
return GistRef(gist_id=gist_id, revision=revision)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def parse_pull_request_event(payload: Mapping[str, Any]) -> PullRequestRef:
|
|
82
|
+
repository = payload.get("repository")
|
|
83
|
+
pull_request = payload.get("pull_request")
|
|
84
|
+
if not isinstance(repository, Mapping) or not isinstance(pull_request, Mapping):
|
|
85
|
+
raise GitHubAppError("Webhook payload is missing repository or pull_request")
|
|
86
|
+
full_name = str(repository.get("full_name") or "")
|
|
87
|
+
if "/" not in full_name:
|
|
88
|
+
raise GitHubAppError("Webhook repository.full_name must be OWNER/REPO")
|
|
89
|
+
number = pull_request.get("number") or payload.get("number")
|
|
90
|
+
try:
|
|
91
|
+
pr_number = int(number)
|
|
92
|
+
except (TypeError, ValueError) as exc:
|
|
93
|
+
raise GitHubAppError("Webhook pull request number must be an integer") from exc
|
|
94
|
+
owner, repo = full_name.split("/", 1)
|
|
95
|
+
if not owner or not repo:
|
|
96
|
+
raise GitHubAppError("Webhook repository.full_name must be OWNER/REPO")
|
|
97
|
+
if pr_number <= 0:
|
|
98
|
+
raise GitHubAppError("Webhook pull request number must be positive")
|
|
99
|
+
return PullRequestRef(owner=owner, repo=repo, number=pr_number)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def build_check_run_payload(
|
|
103
|
+
*,
|
|
104
|
+
name: str,
|
|
105
|
+
head_sha: str,
|
|
106
|
+
summary_markdown: str,
|
|
107
|
+
passed: bool,
|
|
108
|
+
details_url: str | None = None,
|
|
109
|
+
) -> dict[str, Any]:
|
|
110
|
+
conclusion = "success" if passed else "failure"
|
|
111
|
+
payload: dict[str, Any] = {
|
|
112
|
+
"name": name,
|
|
113
|
+
"head_sha": head_sha,
|
|
114
|
+
"status": "completed",
|
|
115
|
+
"conclusion": conclusion,
|
|
116
|
+
"output": {
|
|
117
|
+
"title": "IntentumDiff semantic review",
|
|
118
|
+
"summary": summary_markdown,
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
if details_url:
|
|
122
|
+
payload["details_url"] = details_url
|
|
123
|
+
return payload
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def build_review_result_from_payload(payload: Mapping[str, Any]) -> GitHubAppReviewResult:
|
|
127
|
+
"""Build deterministic local review artifacts from injectable webhook payload data."""
|
|
128
|
+
|
|
129
|
+
review = payload.get("intentumdiff_review")
|
|
130
|
+
if not isinstance(review, Mapping):
|
|
131
|
+
review = {}
|
|
132
|
+
checked_files = _non_negative_int(review.get("checked_files"), default=0)
|
|
133
|
+
semantic_changes = _non_negative_int(review.get("semantic_changes"), default=0)
|
|
134
|
+
guardrail_violations = _non_negative_int(review.get("guardrail_violations"), default=0)
|
|
135
|
+
passed = bool(review.get("passed", semantic_changes == 0 and guardrail_violations == 0))
|
|
136
|
+
summary_markdown = render_github_app_summary(
|
|
137
|
+
checked_files=checked_files,
|
|
138
|
+
semantic_changes=semantic_changes,
|
|
139
|
+
guardrail_violations=guardrail_violations,
|
|
140
|
+
passed=passed,
|
|
141
|
+
)
|
|
142
|
+
html_report = render_github_app_html_report(
|
|
143
|
+
checked_files=checked_files,
|
|
144
|
+
semantic_changes=semantic_changes,
|
|
145
|
+
guardrail_violations=guardrail_violations,
|
|
146
|
+
passed=passed,
|
|
147
|
+
)
|
|
148
|
+
return GitHubAppReviewResult(
|
|
149
|
+
checked_files=checked_files,
|
|
150
|
+
semantic_changes=semantic_changes,
|
|
151
|
+
guardrail_violations=guardrail_violations,
|
|
152
|
+
passed=passed,
|
|
153
|
+
summary_markdown=summary_markdown,
|
|
154
|
+
html_report=html_report,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def build_pull_request_check_response(
|
|
159
|
+
payload: Mapping[str, Any],
|
|
160
|
+
*,
|
|
161
|
+
details_url: str | None = None,
|
|
162
|
+
review_result: GitHubAppReviewResult | None = None,
|
|
163
|
+
) -> dict[str, Any]:
|
|
164
|
+
pr = parse_pull_request_event(payload)
|
|
165
|
+
pull_request = payload.get("pull_request")
|
|
166
|
+
head = pull_request.get("head") if isinstance(pull_request, Mapping) else None
|
|
167
|
+
head_sha = str(head.get("sha") if isinstance(head, Mapping) else payload.get("after") or "")
|
|
168
|
+
if not head_sha:
|
|
169
|
+
raise GitHubAppError("Webhook pull request head.sha is required for check-run creation")
|
|
170
|
+
result = review_result or build_review_result_from_payload(payload)
|
|
171
|
+
check_run = build_check_run_payload(
|
|
172
|
+
name="IntentumDiff",
|
|
173
|
+
head_sha=head_sha,
|
|
174
|
+
summary_markdown=result.summary_markdown,
|
|
175
|
+
passed=result.passed,
|
|
176
|
+
details_url=details_url,
|
|
177
|
+
)
|
|
178
|
+
return {
|
|
179
|
+
"ok": True,
|
|
180
|
+
"event": "pull_request",
|
|
181
|
+
"owner": pr.owner,
|
|
182
|
+
"repo": pr.repo,
|
|
183
|
+
"number": pr.number,
|
|
184
|
+
"check_run": check_run,
|
|
185
|
+
"artifacts": {
|
|
186
|
+
"summary_markdown": result.summary_markdown,
|
|
187
|
+
"html_report": result.html_report,
|
|
188
|
+
},
|
|
189
|
+
"review": {
|
|
190
|
+
"checked_files": result.checked_files,
|
|
191
|
+
"semantic_changes": result.semantic_changes,
|
|
192
|
+
"guardrail_violations": result.guardrail_violations,
|
|
193
|
+
"passed": result.passed,
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def render_github_app_summary(
|
|
199
|
+
*,
|
|
200
|
+
checked_files: int,
|
|
201
|
+
semantic_changes: int,
|
|
202
|
+
guardrail_violations: int,
|
|
203
|
+
passed: bool,
|
|
204
|
+
) -> str:
|
|
205
|
+
status = "passed" if passed else "needs attention"
|
|
206
|
+
return "\n".join(
|
|
207
|
+
[
|
|
208
|
+
"# IntentumDiff GitHub App Review",
|
|
209
|
+
"",
|
|
210
|
+
f"Status: **{status}**",
|
|
211
|
+
"",
|
|
212
|
+
"| Metric | Count |",
|
|
213
|
+
"|---|---:|",
|
|
214
|
+
f"| Files checked | {checked_files} |",
|
|
215
|
+
f"| Semantic changes | {semantic_changes} |",
|
|
216
|
+
f"| Guardrail violations | {guardrail_violations} |",
|
|
217
|
+
"",
|
|
218
|
+
],
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def render_github_app_html_report(
|
|
223
|
+
*,
|
|
224
|
+
checked_files: int,
|
|
225
|
+
semantic_changes: int,
|
|
226
|
+
guardrail_violations: int,
|
|
227
|
+
passed: bool,
|
|
228
|
+
) -> str:
|
|
229
|
+
status = "passed" if passed else "needs attention"
|
|
230
|
+
metrics = {
|
|
231
|
+
"Files checked": checked_files,
|
|
232
|
+
"Semantic changes": semantic_changes,
|
|
233
|
+
"Guardrail violations": guardrail_violations,
|
|
234
|
+
}
|
|
235
|
+
rows = "".join(
|
|
236
|
+
f"<div class=\"metric\"><strong>{value}</strong><span>{html.escape(label)}</span></div>"
|
|
237
|
+
for label, value in metrics.items()
|
|
238
|
+
)
|
|
239
|
+
return (
|
|
240
|
+
"<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\">"
|
|
241
|
+
"<title>IntentumDiff GitHub App Review</title></head><body>"
|
|
242
|
+
f"<main><h1>IntentumDiff GitHub App Review</h1><p>Status: <strong>{html.escape(status)}</strong></p>"
|
|
243
|
+
f"<section class=\"metrics\">{rows}</section></main></body></html>"
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def decode_webhook_body(body: bytes) -> dict[str, Any]:
|
|
248
|
+
payload = json.loads(body.decode("utf-8"))
|
|
249
|
+
if not isinstance(payload, dict):
|
|
250
|
+
raise GitHubAppError("Webhook JSON body must be an object")
|
|
251
|
+
return payload
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _non_negative_int(value: Any, *, default: int) -> int:
|
|
255
|
+
try:
|
|
256
|
+
parsed = int(value)
|
|
257
|
+
except (TypeError, ValueError):
|
|
258
|
+
return default
|
|
259
|
+
return max(parsed, 0)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def create_app() -> Any:
|
|
263
|
+
"""Create the optional FastAPI app without making FastAPI a core dependency."""
|
|
264
|
+
|
|
265
|
+
try:
|
|
266
|
+
from fastapi import FastAPI, Header, HTTPException, Request
|
|
267
|
+
except ImportError as exc: # pragma: no cover - exercised when optional extra absent.
|
|
268
|
+
raise RuntimeError("Install intentumdiff[serve] to run the GitHub App server.") from exc
|
|
269
|
+
|
|
270
|
+
app = FastAPI(title="IntentumDiff GitHub App")
|
|
271
|
+
|
|
272
|
+
@app.post("/github/webhook")
|
|
273
|
+
async def github_webhook(
|
|
274
|
+
request: Request,
|
|
275
|
+
x_github_event: str = Header(default=""),
|
|
276
|
+
x_hub_signature_256: str | None = Header(default=None),
|
|
277
|
+
) -> dict[str, Any]:
|
|
278
|
+
body = await request.body()
|
|
279
|
+
secret = request.app.state.webhook_secret if hasattr(request.app.state, "webhook_secret") else ""
|
|
280
|
+
if secret and not verify_webhook_signature(secret, body, x_hub_signature_256):
|
|
281
|
+
raise HTTPException(status_code=401, detail="invalid signature")
|
|
282
|
+
payload = decode_webhook_body(body)
|
|
283
|
+
if x_github_event == "pull_request":
|
|
284
|
+
return build_pull_request_check_response(payload)
|
|
285
|
+
return {"ok": True, "event": x_github_event}
|
|
286
|
+
|
|
287
|
+
return app
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# auto-generated file
|
|
2
|
+
import _cffi_backend
|
|
3
|
+
|
|
4
|
+
ffi = _cffi_backend.FFI('ffi',
|
|
5
|
+
_version = 0x2601,
|
|
6
|
+
_types = b'\x00\x00\x05\x0D\x00\x00\x07\x03\x00\x00\x01\x11\x00\x00\x00\x0F\x00\x00\x08\x0D\x00\x00\x07\x03\x00\x00\x00\x0F\x00\x00\x02\x01\x00\x00\x00\x01',
|
|
7
|
+
_globals = (b'\x00\x00\x00\x23intentumdiff_call',0,b'\x00\x00\x04\x23intentumdiff_free',0),
|
|
8
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://intentumdiff.local/schemas/invariances/rules.schema.json",
|
|
4
|
+
"title": "IntentumDiff Invariance Rules",
|
|
5
|
+
"description": "Declarative invariance rule catalogue and runtime rule definitions for IntentumDiff.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["version", "rules"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"version": {
|
|
11
|
+
"type": "integer",
|
|
12
|
+
"minimum": 1
|
|
13
|
+
},
|
|
14
|
+
"rules": {
|
|
15
|
+
"type": "array",
|
|
16
|
+
"items": {
|
|
17
|
+
"$ref": "#/$defs/rule"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"$defs": {
|
|
22
|
+
"changeGroupKind": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"enum": [
|
|
25
|
+
"MOVED_CODE",
|
|
26
|
+
"REFACTORING",
|
|
27
|
+
"MEANINGFUL_CHANGE",
|
|
28
|
+
"IGNORED_STYLE",
|
|
29
|
+
"NOISE_SUPPRESSED"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"equivalenceKind": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": [
|
|
35
|
+
"syntactic_trivia",
|
|
36
|
+
"grammar_equivalence",
|
|
37
|
+
"canonical_value_equivalence",
|
|
38
|
+
"unordered_collection_equivalence",
|
|
39
|
+
"contextual_equivalence",
|
|
40
|
+
"refactoring_equivalence"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"evaluator": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"enum": [
|
|
46
|
+
"css_color_equivalence",
|
|
47
|
+
"formatting_suppression_evidence",
|
|
48
|
+
"integer_literal_equivalence",
|
|
49
|
+
"style_only_shortcut_evidence",
|
|
50
|
+
"string_literal_equivalence"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"language": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"enum": [
|
|
56
|
+
"abap",
|
|
57
|
+
"adf",
|
|
58
|
+
"asciidoc",
|
|
59
|
+
"asm",
|
|
60
|
+
"assemblyscript",
|
|
61
|
+
"astro",
|
|
62
|
+
"bash",
|
|
63
|
+
"c",
|
|
64
|
+
"clojure",
|
|
65
|
+
"cpp",
|
|
66
|
+
"csharp",
|
|
67
|
+
"css",
|
|
68
|
+
"dart",
|
|
69
|
+
"databricks-workflow",
|
|
70
|
+
"dax",
|
|
71
|
+
"delphi",
|
|
72
|
+
"dockerfile",
|
|
73
|
+
"elixir",
|
|
74
|
+
"generic",
|
|
75
|
+
"gitignore",
|
|
76
|
+
"go",
|
|
77
|
+
"graphql",
|
|
78
|
+
"groovy",
|
|
79
|
+
"haskell",
|
|
80
|
+
"hcl",
|
|
81
|
+
"html",
|
|
82
|
+
"java",
|
|
83
|
+
"javascript",
|
|
84
|
+
"json",
|
|
85
|
+
"kotlin",
|
|
86
|
+
"latex",
|
|
87
|
+
"lua",
|
|
88
|
+
"m",
|
|
89
|
+
"markdown",
|
|
90
|
+
"ini",
|
|
91
|
+
"gomod",
|
|
92
|
+
"make",
|
|
93
|
+
"cmake",
|
|
94
|
+
"proto",
|
|
95
|
+
"toml",
|
|
96
|
+
"mdx",
|
|
97
|
+
"odin",
|
|
98
|
+
"ocaml",
|
|
99
|
+
"perl",
|
|
100
|
+
"php",
|
|
101
|
+
"plsql",
|
|
102
|
+
"po",
|
|
103
|
+
"postscript",
|
|
104
|
+
"powershell",
|
|
105
|
+
"puppet",
|
|
106
|
+
"python",
|
|
107
|
+
"qsharp",
|
|
108
|
+
"r",
|
|
109
|
+
"reasonml",
|
|
110
|
+
"ruby",
|
|
111
|
+
"rust",
|
|
112
|
+
"sas",
|
|
113
|
+
"scala",
|
|
114
|
+
"scss",
|
|
115
|
+
"sql",
|
|
116
|
+
"squirrel",
|
|
117
|
+
"svelte",
|
|
118
|
+
"swift",
|
|
119
|
+
"tsx",
|
|
120
|
+
"tsql",
|
|
121
|
+
"typescript",
|
|
122
|
+
"vbnet",
|
|
123
|
+
"vue",
|
|
124
|
+
"wat",
|
|
125
|
+
"xml",
|
|
126
|
+
"yaml",
|
|
127
|
+
"zig"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"risk": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"enum": ["green", "amber", "red"]
|
|
133
|
+
},
|
|
134
|
+
"stage": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"enum": [
|
|
137
|
+
"parser_normalization",
|
|
138
|
+
"matcher_scoring",
|
|
139
|
+
"post_diff_refinement",
|
|
140
|
+
"group_emission"
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
"status": {
|
|
144
|
+
"type": "string",
|
|
145
|
+
"enum": ["implemented", "catalog"]
|
|
146
|
+
},
|
|
147
|
+
"stringArray": {
|
|
148
|
+
"type": "array",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "string",
|
|
151
|
+
"minLength": 1
|
|
152
|
+
},
|
|
153
|
+
"uniqueItems": true
|
|
154
|
+
},
|
|
155
|
+
"example": {
|
|
156
|
+
"type": "object",
|
|
157
|
+
"additionalProperties": true
|
|
158
|
+
},
|
|
159
|
+
"rule": {
|
|
160
|
+
"type": "object",
|
|
161
|
+
"additionalProperties": false,
|
|
162
|
+
"required": [
|
|
163
|
+
"id",
|
|
164
|
+
"languages",
|
|
165
|
+
"status",
|
|
166
|
+
"evaluator",
|
|
167
|
+
"group_kind",
|
|
168
|
+
"enabled",
|
|
169
|
+
"risk",
|
|
170
|
+
"equivalence_kind",
|
|
171
|
+
"explanation"
|
|
172
|
+
],
|
|
173
|
+
"properties": {
|
|
174
|
+
"id": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"minLength": 1,
|
|
177
|
+
"pattern": "^[a-z0-9_.-]+$"
|
|
178
|
+
},
|
|
179
|
+
"languages": {
|
|
180
|
+
"type": "array",
|
|
181
|
+
"minItems": 1,
|
|
182
|
+
"uniqueItems": true,
|
|
183
|
+
"items": {
|
|
184
|
+
"$ref": "#/$defs/language"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"status": {
|
|
188
|
+
"$ref": "#/$defs/status"
|
|
189
|
+
},
|
|
190
|
+
"evaluator": {
|
|
191
|
+
"oneOf": [
|
|
192
|
+
{
|
|
193
|
+
"$ref": "#/$defs/evaluator"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"type": "null"
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
"node_types": {
|
|
201
|
+
"$ref": "#/$defs/stringArray"
|
|
202
|
+
},
|
|
203
|
+
"group_kind": {
|
|
204
|
+
"$ref": "#/$defs/changeGroupKind"
|
|
205
|
+
},
|
|
206
|
+
"enabled": {
|
|
207
|
+
"type": "boolean"
|
|
208
|
+
},
|
|
209
|
+
"risk": {
|
|
210
|
+
"$ref": "#/$defs/risk"
|
|
211
|
+
},
|
|
212
|
+
"equivalence_kind": {
|
|
213
|
+
"$ref": "#/$defs/equivalenceKind"
|
|
214
|
+
},
|
|
215
|
+
"explanation": {
|
|
216
|
+
"type": "string",
|
|
217
|
+
"minLength": 1
|
|
218
|
+
},
|
|
219
|
+
"examples": {
|
|
220
|
+
"type": "array",
|
|
221
|
+
"items": {
|
|
222
|
+
"$ref": "#/$defs/example"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"stage": {
|
|
226
|
+
"$ref": "#/$defs/stage"
|
|
227
|
+
},
|
|
228
|
+
"guarantee": {
|
|
229
|
+
"type": "string",
|
|
230
|
+
"minLength": 1
|
|
231
|
+
},
|
|
232
|
+
"guards": {
|
|
233
|
+
"$ref": "#/$defs/stringArray"
|
|
234
|
+
},
|
|
235
|
+
"source_refs": {
|
|
236
|
+
"$ref": "#/$defs/stringArray"
|
|
237
|
+
},
|
|
238
|
+
"notes": {
|
|
239
|
+
"type": "string"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
"allOf": [
|
|
243
|
+
{
|
|
244
|
+
"if": {
|
|
245
|
+
"properties": {
|
|
246
|
+
"status": {
|
|
247
|
+
"const": "implemented"
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"required": ["status"]
|
|
251
|
+
},
|
|
252
|
+
"then": {
|
|
253
|
+
"properties": {
|
|
254
|
+
"evaluator": {
|
|
255
|
+
"$ref": "#/$defs/evaluator"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"if": {
|
|
262
|
+
"properties": {
|
|
263
|
+
"status": {
|
|
264
|
+
"const": "catalog"
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
"required": ["status"]
|
|
268
|
+
},
|
|
269
|
+
"then": {
|
|
270
|
+
"properties": {
|
|
271
|
+
"evaluator": {
|
|
272
|
+
"type": "null"
|
|
273
|
+
},
|
|
274
|
+
"enabled": {
|
|
275
|
+
"const": false
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|