You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(rust): port config simulate to native Rust (Phase 1.3b) (#1298)
Completes the config pilot. Second native command, flipped in
PORT_STATUS.toml from ``shimmed`` to ``native``.
## What ports natively
``mergify config simulate PULL_REQUEST_URL [-f PATH] [-t TOKEN] [-u URL]``:
1. Parses the PR URL into ``(owner/repo, number)``. Invalid URLs
are rejected by clap's ``value_parser``, which exits 2 (matching
Python's ``click.BadParameter``).
2. Resolves the config file (same three-location search as
``config validate`` — shared helper in ``paths.rs``).
3. Reads the YAML as a raw string (no parsing — the simulator API
accepts the text verbatim).
4. Resolves the bearer token: explicit ``--token`` → ``MERGIFY_TOKEN``
→ ``GITHUB_TOKEN`` → error. Matches Python's precedence; the
``gh auth token`` subprocess fallback isn't ported yet.
5. Resolves the API URL: explicit ``--api-url`` → ``MERGIFY_API_URL``
→ ``https://api.mergify.com`` default.
6. POSTs ``{"mergify_yml": <content>}`` to
``/v1/repos/<repo>/pulls/<number>/simulator`` via the 1.2b HTTP
client (auth + retry + typed errors).
7. Prints the returned title + summary to stdout.
Rich Markdown rendering of ``summary`` is deliberately deferred —
we print raw Markdown today. Human output drift is allowed by the
compat contract; machine-readable paths aren't affected because
``config simulate`` has no ``--json`` flag in Python either.
## Dispatch
``mergify-cli/src/main.rs`` now carries two clap subcommands
(``validate`` + ``simulate``). The dispatch logic got a light
reshape: on clap parse failure we distinguish "obvious native
intent" (argv contains ``config`` + one of ``validate``/``simulate``)
from "unrecognized command, fall through". Native-intent parse
errors surface clap's formatted error and exit 2; anything else
falls through to the Python shim so unported commands keep working.
## Refactor
The config-path resolver moved from ``validate.rs`` into a shared
``paths.rs`` module so both commands share a single source of
truth for the ``[".mergify.yml", ".mergify/config.yml",
".github/mergify.yml"]`` search list.
## Tests
24 tests in ``mergify-config`` (up from 11 in Phase 1.3):
- 3 for the shared path resolver (moved out of ``validate.rs``)
- 6 for PR URL parsing (happy path + 5 rejection cases)
- 4 for token resolution (explicit, env fallback, error)
- 2 for API URL resolution
- 1 end-to-end wiremock test: POST + JSON body + auth header +
response rendering
Covered by the port-inventory guard: ``PORT_STATUS.toml`` flips
``config simulate`` from ``shimmed`` to ``native``.
Binary size: 8.0 MB → 8.3 MB (small bump from simulate.rs).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments