Skip to content

Commit 4d2e81d

Browse files
jdclaude
andauthored
feat(rust): port config validate to native Rust (Phase 1.3) (#1282)
First native command. Exercises every piece of the foundations work so far — HTTP fetch, JSON-schema validation, output discipline, typed exit codes — and proves the shim-fallback dispatch pattern. ## What ports natively ``mergify config validate [-f PATH]``: 1. Resolves the config file (explicit ``--config-file`` or the first of ``.mergify.yml``, ``.mergify/config.yml``, ``.github/mergify.yml``). 2. Parses it as YAML via ``serde_norway``. Empty files are treated as an empty mapping; non-mapping top-level values are rejected. 3. Fetches the published schema from ``https://docs.mergify.com/mergify-configuration-schema.json`` via the Phase 1.2b HTTP client (30s timeout, retry on 5xx). 4. Validates with the ``jsonschema`` crate (draft-07). 5. Emits a human-readable success line or a sorted, path-prefixed per-error list via ``Output::emit``. Exit codes: success → 0, missing / unparseable / schema violations → 8 (``CONFIGURATION_ERROR``), schema-fetch failure → 6 (``MERGIFY_API_ERROR``). ## Dispatch ``mergify-cli/src/main.rs`` inspects argv for a ``config validate`` pair; if present, it parses with clap and runs the native path. Everything else — including ``config simulate``, every ``stack`` command, the global ``--version`` / ``--help``, plus any invalid invocation — falls through to the Python shim unchanged. Clap is loaded only when a native match is suspected, so unknown flags on un-ported commands still produce Python's click error messages verbatim. ## Smoke-tested against the real docs CDN Missing config → exit 8. Valid config → exit 0. Invalid config → detailed error list + summary, exit 8. ``mergify --version`` still falls through to Python. ## Test coverage 11 unit tests in ``mergify-config``: - ``resolve_config_path`` with explicit, default, and missing paths - ``load_yaml`` happy path, scalar rejection, malformed YAML, empty-file-is-empty-mapping - ``validate_against_schema`` happy path + error aggregation - ``emit_result`` for success and failure rendering ## Binary size 2.7 MB → 8.0 MB. The jump is jsonschema pulling fancy-regex + the referencing crate's schema resolver. Still well under the 15 MB design target; we can trim with features later if needed. ## Follow-up - 1.3b: port ``config simulate`` - 1.4+: ``ci`` commands (first CI-facing wins for the port story) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0f08f9d commit 4d2e81d

6 files changed

Lines changed: 1022 additions & 13 deletions

File tree

0 commit comments

Comments
 (0)