feat(rust): port config validate to native Rust (Phase 1.3)#1282
Conversation
Member
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Apr 21, 2026
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 👀 Review RequirementsWaiting for:
This rule is failing.
🔴 🔎 ReviewsWaiting for:
This rule is failing.
🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
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> Change-Id: I52ffe9eb817c1879c467c22e2827cbe4c0a4e327
08627d5 to
8b898c2
Compare
Member
Author
Revision history
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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]:--config-fileor thefirst of
.mergify.yml,.mergify/config.yml,.github/mergify.yml).serde_norway. Empty files are treatedas an empty mapping; non-mapping top-level values are rejected.
https://docs.mergify.com/mergify-configuration-schema.jsonvia the Phase 1.2b HTTP client (30s timeout, retry on 5xx).
jsonschemacrate (draft-07).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.rsinspects argv for aconfig validatepair; if present, it parses with clap and runs the native path.
Everything else — including
config simulate, everystackcommand, the global
--version/--help, plus any invalidinvocation — 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 --versionstillfalls through to Python.
Test coverage
11 unit tests in
mergify-config:resolve_config_pathwith explicit, default, and missing pathsload_yamlhappy path, scalar rejection, malformed YAML,empty-file-is-empty-mapping
validate_against_schemahappy path + error aggregationemit_resultfor success and failure renderingBinary 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
config simulatecicommands (first CI-facing wins for the port story)Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Depends-On: #1281