feat: add --publish-to-uq flag for understand-quickly registry integration#449
feat: add --publish-to-uq flag for understand-quickly registry integration#449amacsmith wants to merge 2 commits intotirth8205:mainfrom
Conversation
…ation Adds a new opt-in publish path on the visualize subcommand: - New --format json choice that runs export_graph_data() and writes a registry-shaped JSON to <data_dir>/graph.json with a metadata block (tool, tool_version, generated_at, commit). - New --publish-to-uq flag that, after the JSON write, fires a repository_dispatch (event_type=sync-entry) at looptech-ai/understand-quickly so the registry resyncs the entry. Implies --format json. Owner/repo is derived from `git remote get-url origin`. Soft-fail behavior: - Without UNDERSTAND_QUICKLY_TOKEN, the JSON is still written and the dispatch is skipped with a one-line informational message — the registry's nightly sync will pick the change up. - HTTP failures (e.g. unregistered repo) print a one-liner pointing at `npx @understand-quickly/cli add`; the visualize run still exits 0. Existing visualize invocations are unchanged. Default format remains html. The new module lives in code_review_graph/publish.py with unit tests in tests/test_publish.py covering metadata embedding, the no-token soft skip, the happy-path dispatch (mocked urlopen), HTTP failure handling, and origin URL parsing for both ssh and https. Background: looptech-ai/understand-quickly is a public registry of code-knowledge graphs that supports code-review-graph as a first-class format (code-review-graph@1). This wires the existing export pipeline into the registry's documented protocol. Refs: https://github.com/looptech-ai/understand-quickly/blob/main/docs/integrations/protocol.md
There was a problem hiding this comment.
Pull request overview
Adds an opt-in integration to publish a code-review-graph@1-compatible JSON artifact and (optionally) trigger an understand-quickly registry resync from the visualize command.
Changes:
- Adds
jsonas avisualize --formatoption and writes.code-review-graph/graph.json. - Introduces
--publish-to-uqonvisualizeto (optionally) fire arepository_dispatchtolooptech-ai/understand-quickly. - Adds a new
code_review_graph/publish.pymodule plus unit tests covering payload metadata, JSON output, dispatch behavior, and git remote parsing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tests/test_publish.py |
Adds unit tests for JSON export payload + dispatch soft-fail behavior and git remote parsing. |
README.md |
Documents --format json and --publish-to-uq usage. |
code_review_graph/publish.py |
Implements JSON export with metadata and optional GitHub repository_dispatch publish step. |
code_review_graph/cli.py |
Wires json format and the new --publish-to-uq flag into the visualize command flow. |
| if publish_to_uq and fmt == "html": | ||
| fmt = "json" | ||
|
|
||
| if fmt == "json" or publish_to_uq: |
There was a problem hiding this comment.
Fixed in 314178b. The override is now if publish_to_uq and fmt != "json": and emits a stderr warning when the user explicitly passed a non-json/non-html format (html is the default, so we don't warn for it). Behavior now matches the help text — --publish-to-uq always implies --format json, surprises eliminated.
| metadata block looptech-ai/understand-quickly expects, writes the result to | ||
| ``<data_dir>/graph.json``, and optionally fires a ``repository_dispatch`` so | ||
| the registry resyncs the entry. Gated on ``UNDERSTAND_QUICKLY_TOKEN`` — without | ||
| it, the JSON is still written and the dispatch is skipped silently. |
There was a problem hiding this comment.
Fixed in 314178b. Aligned the docstring with the actual behavior: the token-missing path prints an informational message pointing at the nightly-sync fallback rather than failing silently. Kept the print() to preserve discoverability for users running --publish-to-uq without a token configured.
| def write_publish_json(store: GraphStore, repo_root: Path, output_path: Path) -> Path: | ||
| payload = build_publish_payload(store, repo_root) | ||
| output_path.parent.mkdir(parents=True, exist_ok=True) | ||
| output_path.write_text(json.dumps(payload, indent=2, default=str)) |
There was a problem hiding this comment.
Fixed in 314178b. write_publish_json() now passes encoding="utf-8" to Path.write_text(), matching the rest of the repo's file-write conventions and avoiding platform-dependent encodings on Windows.
- Force fmt='json' whenever --publish-to-uq is set; warn on explicit --format conflict (Copilot: cli.py:1015 silent override). - Align publish.py module docstring with actual behavior — token-missing branch prints an informational message rather than skipping silently. - Pass encoding='utf-8' to write_text() to match other file outputs and avoid platform-dependent encodings on Windows. Signed-off-by: Alex Macdonald-Smith <alex.macsmith@gmail.com>
|
Thanks @copilot — all three review items addressed in
Tests: |
Why
looptech-ai/understand-quicklyis a public registry of code-knowledge graphs with an MCP server and a stableregistry.jsonAPI. code-review-graph is one of the first-class formats it already supports (code-review-graph@1). Wiring a--publish-to-uqflag into the existingvisualizesubcommand means any user who runs code-review-graph can land in the registry with one flag — and AI agents using the registry's MCP server can consume the graph immediately..code-review-graph/graph.json) and are fetched fromraw.githubusercontent.com; the registry only stores pointers.metadata.commitis set), MCP server out of the box.What changes
jsonto the existing--formatchoices onvisualize. Runsexport_graph_data()(the same dict the other formats are built from) and writes it to<data_dir>/graph.json(i.e..code-review-graph/graph.json).--publish-to-uqflag onvisualize. Implies--format json. After the JSON is written, fires arepository_dispatch(event_type=sync-entry) atlooptech-ai/understand-quicklyso the registry resyncs the entry. Owner/repo is derived fromgit remote get-url origin.metadata.tool,metadata.tool_version,metadata.generated_at, and (when in a git checkout)metadata.commit = git rev-parse HEADon the exported dict alongside the existingnodes,edges,stats,flows,communitiesfields.code_review_graph/publish.pymodule; thevisualizehandler delegates to it. Stdlib only (urllib.request) — no new dependencies.--formatexamples.No-op default
--publish-to-uqis opt-in. Existingvisualizeinvocations are unaffected. With the flag set butUNDERSTAND_QUICKLY_TOKENunset, the tool writes the local artifact as usual and prints one informational line — no network call, no exit-1. Same soft-fail behavior on HTTP errors (e.g. an unregistered repo): the JSON is written, a one-liner points atnpx @understand-quickly/cli add, exit 0.Token setup
The user adds a fine-grained GitHub PAT to their environment (or repo secrets, when run from CI):
looptech-ai/understand-quicklyonly.Repository dispatches: write. Nothing else.A drop-in workflow snippet lives at
docs/integrations/sample-publish-workflow.yml.Test plan
Unit tests added in
tests/test_publish.py(9 cases) cover:visualizewithout the flag (default--format html) is unchanged — the full existing suite still passes (1245 passed, 1 skipped, 2 xpassed locally).build_publish_payload()embedsmetadata.tool == \"code-review-graph\",metadata.tool_version, and an ISO-8601metadata.generated_at.metadata.commitis a 40-hex sha when present.--publish-to-uqwithUNDERSTAND_QUICKLY_TOKENunset writes the JSON and printsUNDERSTAND_QUICKLY_TOKEN not set; skipping repository_dispatch—urlopenis never called.--publish-to-uqwith the token set fires a single POST tohttps://api.github.com/repos/looptech-ai/understand-quickly/dispatcheswith body{\"event_type\":\"sync-entry\",\"client_payload\":{\"id\":\"<owner>/<repo>\"}}and anAuthorization: Bearer ...header (mockedurlopen).HTTPErrorfrom the dispatch (e.g. unregistered repo, 422) is soft-failed: the run still writes the JSON, printsdispatch failed ... npx @understand-quickly/cli add, and exits 0.git remote get-url originparsing handles bothhttps://github.com/owner/repo(.git)andgit@github.com:owner/repo(.git)shapes.Manual smoke (optional):
code-review-graph build && code-review-graph visualize --format jsonwrites.code-review-graph/graph.jsonwithmetadata.commitmatchinggit rev-parse HEAD.Notes for the maintainer
tirth8205/code-review-graphto the verified-publisher allowlist for auto-merge of registry updates.--publishvs--publish-to-uq), the JSON output path, or factor the publish module differently if you'd prefer.Links
code-review-graph@1schema: https://github.com/looptech-ai/understand-quickly/blob/main/schemas/code-review-graph@1.json