feat(rust): port stack checkout to native Rust#1522
Draft
Conversation
Member
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Jun 3, 2026
This was referenced Jun 3, 2026
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 ⛓️ Depends-On RequirementsWaiting for
This rule is failing.Requirement based on the presence of
🔴 👀 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.
|
The Rust binary now serves ``mergify stack checkout <NAME>`` natively. ``mergify_cli/stack/checkout.py``, ``mergify_cli/tests/stack/test_checkout.py``, and the click registration are removed in the same PR. First GitHub-API-backed stack subcommand to land natively. The slice introduces a shared ``mergify_stack::stack_context`` module that resolves the per-command preamble — repository owner/repo, GitHub API server URL, default branch prefix — that ``sync``, ``list``, ``open``, and ``push`` will all reuse when their ports follow. ``mergify_stack::stack_context``: - ``parse_slug`` — owner/repo extraction handling both ``https://github.com/o/r.git`` and ``git@github.com:o/r.git`` shapes, port of ``utils.get_slug``. - ``resolve_repo`` — explicit ``--repository OWNER/REPO`` takes precedence; otherwise we parse ``git config remote.<remote>.url``. - ``resolve_github_server`` — reads ``mergify-cli.github-server`` git config, falls back to ``https://api.github.com/``, mirrors Python's https-coercion + ``/api/v3`` suffix for GitHub Enterprise. - ``resolve_default_branch_prefix`` — reads ``mergify-cli.stack-branch-prefix``, falls back to ``stack/<author>``. ``mergify_stack::commands::checkout``: 1. Normalises the ``NAME`` argument — strip any trailing ``/Ixxxx…`` Change-Id suffix (via the new ``change_id::strip_branch_suffix`` helper) and any leading ``<branch_prefix>/`` so users can paste a leaf branch ref verbatim. 2. Searches GitHub for the stack's PRs via the existing ``mergify_stack::remote_changes::get_remote_changes``. 3. Builds the open-PR chain from root to leaf — root is the PR whose ``base.ref`` doesn't start with the stack branch prefix; we walk up via ``head.ref`` → ``base.ref`` linking. Two roots surface as ``InvalidState``, matching Python. 4. ``--dry-run`` short-circuits with the printed chain. Otherwise ``git fetch <remote> <leaf-head>``, ``git checkout -b <local> <remote>/<leaf-head>``, ``git branch --set-upstream-to=<remote>/<root-base>``. Binary handler resolves the trunk via ``--trunk REMOTE/BRANCH`` or the existing ``mergify_stack::trunk::get_trunk`` fallback, the token via ``mergify_core::auth::resolve_token``, and the author via either ``--author`` or ``GET /user`` against the resolved client. Coverage in ``crates/mergify-stack/src/commands/checkout.rs`` (7 tests): the pure chain builder (root-to-leaf, closed-PR filter, two-root detection, empty case) plus three end-to-end ``run`` tests against wiremock — no-stacked-prs, dry-run returns chain without touching git, name normalisation strips both the Change-Id suffix and the branch prefix. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Change-Id: I71e74cae43846d9708bef9c57d32ba81b8499edc
9342e5c to
f86d325
Compare
0da0845 to
b09a7f8
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.
The Rust binary now serves
mergify stack checkout <NAME>natively.
mergify_cli/stack/checkout.py,mergify_cli/tests/stack/test_checkout.py, and the clickregistration are removed in the same PR.
First GitHub-API-backed stack subcommand to land natively. The
slice introduces a shared
mergify_stack::stack_contextmodulethat resolves the per-command preamble — repository owner/repo,
GitHub API server URL, default branch prefix — that
sync,list,open, andpushwill all reuse when their portsfollow.
mergify_stack::stack_context:parse_slug— owner/repo extraction handling bothhttps://github.com/o/r.gitandgit@github.com:o/r.gitshapes, port of
utils.get_slug.resolve_repo— explicit--repository OWNER/REPOtakes precedence; otherwise we parse
git config remote.<remote>.url.resolve_github_server— readsmergify-cli.github-servergit config, falls back tohttps://api.github.com/, mirrors Python's https-coercion +/api/v3suffix for GitHub Enterprise.resolve_default_branch_prefix— readsmergify-cli.stack-branch-prefix, falls back tostack/<author>.mergify_stack::commands::checkout:NAMEargument — strip any trailing/Ixxxx…Change-Id suffix (via the newchange_id::strip_branch_suffixhelper) and any leading<branch_prefix>/so users can paste a leaf branch refverbatim.
mergify_stack::remote_changes::get_remote_changes.whose
base.refdoesn't start with the stack branchprefix; we walk up via
head.ref→base.reflinking.Two roots surface as
InvalidState, matching Python.--dry-runshort-circuits with the printed chain.Otherwise
git fetch <remote> <leaf-head>,git checkout -b <local> <remote>/<leaf-head>,git branch --set-upstream-to=<remote>/<root-base>.Binary handler resolves the trunk via
--trunk REMOTE/BRANCHor the existing
mergify_stack::trunk::get_trunkfallback,the token via
mergify_core::auth::resolve_token, and theauthor via either
--authororGET /useragainst theresolved client.
Coverage in
crates/mergify-stack/src/commands/checkout.rs(7 tests): the pure chain builder (root-to-leaf, closed-PR
filter, two-root detection, empty case) plus three end-to-end
runtests against wiremock — no-stacked-prs, dry-run returnschain without touching git, name normalisation strips both the
Change-Id suffix and the branch prefix.
Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com
Depends-On: #1521