Skip to content

feat(rust): port ci git-refs to native Rust#1405

Merged
mergify[bot] merged 2 commits into
mainfrom
devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47
May 12, 2026
Merged

feat(rust): port ci git-refs to native Rust#1405
mergify[bot] merged 2 commits into
mainfrom
devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented May 11, 2026

The Rust binary now serves mergify ci git-refs natively. The
Python implementation (mergify_cli/ci/cli.py:git_refs) and
its tests are removed in the same PR — port-and-delete keeps a
single live copy.

The previous commit landed a live-smoke test pinning the
Base: HEAD^ / Head: HEAD fallback contract. That same
test now exercises the Rust path.

The command detects the base/head git references for the
current build:

  1. Buildkite env (BUILDKITE_PULL_REQUEST and friends)
  2. GitHub Actions event payload at $GITHUB_EVENT_PATH
  3. refs/notes/mergify/<branch> git notes (for merge-queue
    draft PRs created by the Mergify backend)
  4. The MQ PR body's YAML metadata block (fallback for tools
    that can't read git notes)
  5. Literal HEAD^..HEAD when none of the above match

Three output formats:

  • text (default): Base: <ref> and Head: <ref> on
    two lines.
  • shell: MERGIFY_GIT_REFS_{BASE,HEAD,SOURCE}=... lines
    for eval; values are properly shell-quoted.
  • json: a single JSON object {"base":..., "head":..., "source":...}.

The command also writes base=...\nhead=... to
$GITHUB_OUTPUT when set, and calls buildkite-agent meta-data set when BUILDKITE=true.

This commit introduces two shared helper modules in the
mergify-ci crate that the next port (ci queue-info)
will reuse:

  • github_event: GitHub Actions event payload deserialization
    (GITHUB_EVENT_PATH).
  • queue_metadata: MQ YAML fenced-block extraction from PR
    bodies and git notes.

The notes reader is injected as a trait-object callback so unit
tests can exercise the note-driven detection path without
touching a real git repository; the production path shells out
via real_notes_reader.

Adds the serde_yaml_ng dep (YAML parser) to the
mergify-ci crate.

12 new git-refs + 2 format round-trip tests plus 8
event/metadata tests in the shared helpers. The Python
git-refs tests in mergify_cli/tests/ci/test_cli.py are
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Depends-On: #1404

@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 11, 2026 11:46 Failure
@jd jd had a problem deploying to func-tests-live May 11, 2026 11:46 — with GitHub Actions Failure
@jd
Copy link
Copy Markdown
Member Author

jd commented May 11, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 test(ci): add live smoke test for ci git-refs #1404
2 feat(rust): port ci git-refs to native Rust #1405 👈
3 test(ci): add live smoke test for ci queue-info #1406
4 feat(rust): port ci queue-info to native Rust #1407
5 test(queue): add live smoke test for queue status #1409
6 feat(rust): port queue status to native Rust #1359
7 test: derive native queue commands from the binary, not a hardcoded list #1366
8 test(queue): add live smoke test for queue show #1408
9 feat(rust): port queue show to native Rust #1399
10 test(skill): port the skill-references test to Rust #1414

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 11, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 ⛓️ Depends-On Requirements

Wonderful, this rule succeeded.

Requirement based on the presence of Depends-On in the body of the pull request

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

@mergify mergify Bot requested a review from a team May 11, 2026 12:00
@jd jd marked this pull request as ready for review May 11, 2026 12:03
@jd jd force-pushed the devs/jd/worktree-rust-port/add-live-smoke-test-ci-git-refs--ae0e3fe5 branch from bc6091b to dc79f69 Compare May 11, 2026 14:07
@jd jd force-pushed the devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47 branch from 2d49d23 to 0d7c20c Compare May 11, 2026 14:07
@jd jd temporarily deployed to func-tests-live May 11, 2026 14:07 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 11, 2026 14:07 — with GitHub Actions Inactive
@jd
Copy link
Copy Markdown
Member Author

jd commented May 11, 2026

Revision history

# Type Changes Reason Date
1 initial 2d49d23 2026-05-11 14:08 UTC
2 rebase 2d49d23 → 0d7c20c 2026-05-11 14:08 UTC
3 rebase 0d7c20c → d0a28d3 2026-05-11 14:59 UTC
4 rebase d0a28d3 → c12b430 2026-05-11 20:59 UTC
5 rebase c12b430 → a9ed3f2 (rebase only) 2026-05-12 07:44 UTC

@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 11, 2026 14:08 Failure
@jd jd force-pushed the devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47 branch from 0d7c20c to d0a28d3 Compare May 11, 2026 14:59
@jd jd temporarily deployed to func-tests-live May 11, 2026 14:59 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 11, 2026 14:59 Failure
@jd jd force-pushed the devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47 branch from d0a28d3 to c12b430 Compare May 11, 2026 20:59
@jd jd temporarily deployed to func-tests-live May 11, 2026 20:59 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 11, 2026 20:59 Failure
@jd jd requested a review from Copilot May 12, 2026 07:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports mergify ci git-refs from the Python click CLI to a native Rust implementation in the mergify-ci crate, and wires the Rust binary dispatcher to run it natively (while removing the Python CLI entrypoint/tests for this command).

Changes:

  • Add native Rust ci git-refs command with base/head detection, multiple output formats, and CI side-effects (GITHUB_OUTPUT / Buildkite meta-data).
  • Introduce shared Rust helpers for GitHub Actions event payload parsing and merge-queue YAML metadata extraction.
  • Remove the Python click git_refs command and its CLI-level tests; register ci git-refs as a native subcommand in the Rust mergify binary.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mergify_cli/tests/ci/test_cli.py Removes Python CLI tests for ci git-refs now that execution is native Rust.
mergify_cli/ci/cli.py Deletes the Python click ci git-refs command implementation (now handled by Rust).
crates/mergify-cli/src/main.rs Adds native dispatch + clap plumbing for mergify ci git-refs --format ....
crates/mergify-ci/src/lib.rs Exposes new git_refs, github_event, and queue_metadata modules.
crates/mergify-ci/src/github_event.rs Adds GitHub Actions event payload deserialization + loader.
crates/mergify-ci/src/queue_metadata.rs Adds MQ PR-body fenced YAML extraction + detection helper.
crates/mergify-ci/src/git_refs.rs Implements detection logic, output formats, and CI side-effects for ci git-refs.
crates/mergify-ci/Cargo.toml Adds serde_yaml_ng dependency for YAML parsing.
Cargo.lock Locks new dependencies (including serde_yaml_ng) and transitive updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/mergify-ci/src/git_refs.rs
Comment thread crates/mergify-ci/src/git_refs.rs
jd and others added 2 commits May 12, 2026 09:38
Pins the contract for ``mergify ci git-refs`` so a future Rust
port can be validated against the same test that exercised the
Python implementation. The next commit ports the command; this
one lands first so it runs against Python at its own CI, then
against Rust on rebase — same test, both ends of the port.

The test runs in the existing live-tests harness but doesn't
need the live token: ``ci git-refs`` is locally evaluated (no
API call). The conftest fixture scrubs every CI provider env
var and runs in a tmp dir, so the detector lands on its literal
``HEAD^..HEAD`` fallback path. The assertion checks for ``Base:
HEAD^`` and ``Head: HEAD`` in stdout — output format that the
Python and Rust implementations share verbatim.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: Iae0e3fe5b4cc3b653529b80ae10bae6c83f3e53d
The Rust binary now serves ``mergify ci git-refs`` natively. The
Python implementation (``mergify_cli/ci/cli.py:git_refs``) and
its tests are removed in the same PR — port-and-delete keeps a
single live copy.

The previous commit landed a live-smoke test pinning the
``Base: HEAD^`` / ``Head: HEAD`` fallback contract. That same
test now exercises the Rust path.

The command detects the base/head git references for the
current build:

1. Buildkite env (``BUILDKITE_PULL_REQUEST`` and friends)
2. GitHub Actions event payload at ``$GITHUB_EVENT_PATH``
3. ``refs/notes/mergify/<branch>`` git notes (for merge-queue
   draft PRs created by the Mergify backend)
4. The MQ PR body's YAML metadata block (fallback for tools
   that can't read git notes)
5. Literal ``HEAD^..HEAD`` when none of the above match

Three output formats:

- ``text`` (default): ``Base: <ref>`` and ``Head: <ref>`` on
  two lines.
- ``shell``: ``MERGIFY_GIT_REFS_{BASE,HEAD,SOURCE}=...`` lines
  for ``eval``; values are properly shell-quoted.
- ``json``: a single JSON object ``{"base":..., "head":...,
  "source":...}``.

The command also writes ``base=...\nhead=...`` to
``$GITHUB_OUTPUT`` when set, and calls ``buildkite-agent
meta-data set`` when ``BUILDKITE=true``.

This commit introduces two shared helper modules in the
``mergify-ci`` crate that the next port (``ci queue-info``)
will reuse:

- ``github_event``: GitHub Actions event payload deserialization
  (``GITHUB_EVENT_PATH``).
- ``queue_metadata``: MQ YAML fenced-block extraction from PR
  bodies and git notes.

The notes reader is injected as a trait-object callback so unit
tests can exercise the note-driven detection path without
touching a real git repository; the production path shells out
via ``real_notes_reader``.

Adds the ``serde_yaml_ng`` dep (YAML parser) to the
``mergify-ci`` crate.

12 new git-refs + 2 format round-trip tests plus 8
event/metadata tests in the shared helpers. The Python
git-refs tests in ``mergify_cli/tests/ci/test_cli.py`` are
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: I9a936b47b90f1128f6fdac6e4f29af6f1525a28c
@jd jd force-pushed the devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47 branch from c12b430 to a9ed3f2 Compare May 12, 2026 07:44
@jd jd force-pushed the devs/jd/worktree-rust-port/add-live-smoke-test-ci-git-refs--ae0e3fe5 branch from 72f013c to 47cefb4 Compare May 12, 2026 07:44
@jd jd temporarily deployed to func-tests-live May 12, 2026 07:44 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 12, 2026 07:44 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 12, 2026 07:44 — with GitHub Actions Inactive
@mergify mergify Bot deployed to Mergify Merge Protections May 12, 2026 07:45 Active
Base automatically changed from devs/jd/worktree-rust-port/add-live-smoke-test-ci-git-refs--ae0e3fe5 to main May 12, 2026 11:28
@mergify mergify Bot requested a review from a team May 12, 2026 12:39
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

Merge Queue Status

This pull request spent 16 minutes 44 seconds in the queue, including 16 minutes 16 seconds running CI.

Required conditions to merge

mergify Bot added a commit that referenced this pull request May 12, 2026
@mergify mergify Bot added the queued label May 12, 2026
@mergify mergify Bot merged commit f8a814d into main May 12, 2026
53 checks passed
@mergify mergify Bot deleted the devs/jd/worktree-rust-port/port-ci-git-refs-native-rust--9a936b47 branch May 12, 2026 14:20
@mergify mergify Bot removed the queued label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants