Skip to content

Commit 3f54bf1

Browse files
jdclaude
andcommitted
feat(rust): port ci scopes-send to native Rust (Phase 1.4)
First ``ci`` command to go native. Straight HTTP POST to Mergify carrying the scopes detected for a pull request, no new infrastructure needed beyond what the config pilot already established. ## What ports natively ``mergify ci scopes-send [-r REPO] [-p NUMBER] [-t TOKEN] [-u URL] [-s SCOPE...] [--scopes-json FILE] [--scopes-file FILE]``: 1. Resolves the repository: ``--repository`` flag → ``GITHUB_REPOSITORY`` env → error. 2. Resolves the pull-request number: ``--pull-request`` flag → ``GITHUB_EVENT_PATH`` JSON (``.pull_request.number``) → ``None``. When ``None`` the command prints a skip message to stderr and returns 0 — matches Python's "no PR, nothing to send". 3. Resolves the token: ``--token`` flag → ``MERGIFY_TOKEN`` → ``GITHUB_TOKEN`` → error. 4. Resolves the API URL: ``--api-url`` flag → ``MERGIFY_API_URL`` → ``https://api.mergify.com``. 5. Collects scopes from up to three sources (combined in order): ``--scope`` repeated flags, ``--scopes-json`` (Pydantic ``DetectedScope`` dump), ``--scopes-file`` (plain text). 6. POSTs ``{"scopes": [...]}`` to ``/v1/repos/<repo>/pulls/<number>/scopes`` via the HTTP client. ``--file`` is a hidden deprecated alias for ``--scopes-json``. When used, the command prints a deprecation warning to stderr and proceeds — matches Python's ``click.echo(..., err=True)``. ## Layout New ``mergify-ci`` crate under ``crates/``. The ``scopes_send`` module is self-contained (duplicates ``resolve_token`` / ``resolve_api_url`` from ``mergify-config::simulate`` for now — they factor into ``mergify-core`` in a follow-up refactor PR once another command needs them). The binary's dispatch gains a ``Ci`` subcommand group, with ``scopes-send`` as its only native variant today. Everything else under ``ci`` (``git-refs``, ``scopes``, ``scopes-send`` siblings) still falls through to the Python shim. The native-intent heuristic in ``detect_native`` now recognizes both the ``config`` and ``ci`` prefixes. ## Tests 11 new unit tests in ``mergify-ci::scopes_send``: - Repository resolution: flag, env fallback, error - Pull-request resolution: explicit, from event JSON, missing - JSON file parsing (DetectedScope shape) - Text file parsing (trims + strips blanks) - End-to-end wiremock: combined scopes from all three sources - End-to-end wiremock: deprecated ``--file`` emits warning - End-to-end wiremock: skip-on-no-PR early-out ``PORT_STATUS.toml`` flips ``ci scopes-send`` from ``shimmed`` to ``native``. The port-guard test stays green. Binary size: 8.3 MB → 8.4 MB. 51 Rust tests total. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Change-Id: I7ff9df90791786c3c26f8159249d91093ba34ec1
1 parent 04d71cb commit 3f54bf1

9 files changed

Lines changed: 674 additions & 233 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PORT_STATUS.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ status = "shimmed"
4747
path = ["ci", "scopes"]
4848
status = "shimmed"
4949

50-
[[command]]
51-
path = ["ci", "scopes-send"]
52-
status = "shimmed"
53-
5450
[[command]]
5551
path = ["freeze", "create"]
5652
status = "shimmed"

crates/mergify-ci/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "mergify-ci"
3+
version = "0.0.0"
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
authors.workspace = true
9+
description = "Native implementation of `mergify ci` subcommands."
10+
publish = false
11+
12+
[dependencies]
13+
mergify-core = { path = "../mergify-core" }
14+
serde = { version = "1.0", features = ["derive"] }
15+
serde_json = "1.0"
16+
url = "2"
17+
18+
[dev-dependencies]
19+
tempfile = "3.14"
20+
temp-env = { version = "0.3", features = ["async_closure"] }
21+
tokio = { version = "1", default-features = false, features = ["macros", "rt", "time"] }
22+
wiremock = "0.6"
23+
24+
[lints]
25+
workspace = true

crates/mergify-ci/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Native Rust implementation of the `mergify ci` subcommands.
2+
//!
3+
//! Phase 1.4 starts with `ci scopes-send` — straight HTTP POST to
4+
//! Mergify with the scopes detected for a pull request. Other ci
5+
//! commands (`git-refs`, `scopes`, `queue-info`, `junit-process`)
6+
//! land in follow-up PRs as the shared infrastructure they need
7+
//! (git-subprocess runner, GitHub event parser, `JUnit` XML reader)
8+
//! is built out.
9+
10+
pub mod scopes_send;

0 commit comments

Comments
 (0)