Skip to content

fix(rust): honor Buildkite/CircleCI/Jenkins env in ci scopes-send#1365

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75
May 5, 2026
Merged

fix(rust): honor Buildkite/CircleCI/Jenkins env in ci scopes-send#1365
mergify[bot] merged 1 commit into
mainfrom
devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75

Conversation

@sileht
Copy link
Copy Markdown
Member

@sileht sileht commented May 5, 2026

The Python ci scopes-send resolves the repository and PR number
through detector.get_github_repository /
get_github_pull_request_number, which match
get_ci_provider() and consult provider-specific env vars
(BUILDKITE_REPO / BUILDKITE_PULL_REQUEST,
CIRCLE_REPOSITORY_URL, GIT_URL). The Rust port only read
GITHUB_REPOSITORY and GITHUB_EVENT_PATH, so on Buildkite it
errored on missing --repository (no GITHUB_REPOSITORY) or
silently skipped because no PR number was detected — making
mergify ci scopes-send unusable outside GitHub Actions.

This brings the Rust resolver in line:

  • detect_ci_provider mirrors the Python provider order
    (Jenkins → GitHub Actions → CircleCI → Buildkite).
  • resolve_repository branches on the detected provider and
    parses BUILDKITE_REPO / CIRCLE_REPOSITORY_URL /
    GIT_URL via a new parse_repo_from_url helper that
    recognizes SSH (git@host:owner/repo[.git]), HTTP(S), and
    bare owner/repo shapes — matching the regex pair in
    _get_github_repository_from_env. GITHUB_REPOSITORY stays
    as the GHA + no-provider fallback.
  • resolve_pull_request reads BUILDKITE_PULL_REQUEST on
    Buildkite (treating empty / false as "no PR"); the
    GitHub-event-path branch is unchanged otherwise.

Tests now clear every CI-provider env var the resolver inspects via
a shared with_ci_env / with_ci_env_async helper before
applying per-test overrides, so they no longer inherit
provider state from the host (e.g. Buildkite's own CI). Adds 10
new tests covering Buildkite / CircleCI / Jenkins repo resolution,
Buildkite PR resolution edge cases (false / unset / number), and
parse_repo_from_url shape coverage. 23/23 tests green; clippy
clean.

Other recent detector.py additions (get_cicd_pipeline_run_url,
get_base_ref_name, get_repository_url, 1-based
BUILDKITE_RETRY_COUNT) feed junit_processing and
ci git-refs; neither is ported to Rust on this branch yet, so
nothing to align there.

Fixes INC-1357

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

Copilot AI review requested due to automatic review settings May 5, 2026 17:20
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 5, 2026 17:20 Failure
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 5, 2026

Merge Protections

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

🟠 🤖 Continuous Integration

Waiting for:

  • check-success=ci-gate
Waiting checks: ci-gate.
  • 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,})

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

This PR updates the Rust implementation of mergify ci scopes-send to resolve repository and pull request information from multiple CI providers (Buildkite/CircleCI/Jenkins) in a way that matches the Python CLI behavior, making the command usable outside GitHub Actions.

Changes:

  • Add CI-provider detection and provider-specific repository resolution (Buildkite/CircleCI/Jenkins) with URL parsing support.
  • Add Buildkite-specific pull request number resolution (BUILDKITE_PULL_REQUEST) with edge-case handling (false/empty).
  • Harden tests by clearing all CI-related env vars before applying per-test overrides; add new tests for the new resolver behavior and URL parsing.

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

Comment thread crates/mergify-ci/src/scopes_send.rs Outdated
@sileht sileht force-pushed the devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75 branch from 789f791 to 87dba74 Compare May 5, 2026 17:25
@sileht
Copy link
Copy Markdown
Member Author

sileht commented May 5, 2026

Revision history

# Type Changes Reason Date
1 initial 789f791 2026-05-05 17:25 UTC
2 content 789f791 → 87dba74 (raw) 2026-05-05 17:25 UTC
3 content 87dba74 → a234636 (raw) 2026-05-05 17:28 UTC
4 content a234636 → 54c69c3 (raw) 2026-05-05 17:30 UTC

@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 5, 2026 17:25 Failure
@sileht sileht force-pushed the devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75 branch from 87dba74 to a234636 Compare May 5, 2026 17:28
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 5, 2026 17:28 Failure
The Python ``ci scopes-send`` resolves the repository and PR number
through ``detector.get_github_repository`` /
``get_github_pull_request_number``, which match
``get_ci_provider()`` and consult provider-specific env vars
(``BUILDKITE_REPO`` / ``BUILDKITE_PULL_REQUEST``,
``CIRCLE_REPOSITORY_URL``, ``GIT_URL``). The Rust port only read
``GITHUB_REPOSITORY`` and ``GITHUB_EVENT_PATH``, so on Buildkite it
errored on missing ``--repository`` (no ``GITHUB_REPOSITORY``) or
silently skipped because no PR number was detected — making
``mergify ci scopes-send`` unusable outside GitHub Actions.

Mirror the relevant slice of ``mergify_cli/ci/detector.py`` as a
new ``mergify_ci::detector`` module so both languages share the
same provider-detection contract:

- ``CIProvider`` enum + ``get_ci_provider()`` mirror Python's
  ``CIProviderT`` and the Jenkins → GitHub Actions → CircleCI →
  Buildkite ordering.
- ``get_github_repository()`` returns ``GITHUB_REPOSITORY`` on GHA
  and parses ``BUILDKITE_REPO`` / ``CIRCLE_REPOSITORY_URL`` /
  ``GIT_URL`` for the other providers via a
  ``parse_repository_url`` helper that recognizes SSH
  (``git@host:owner/repo[.git]``), HTTP(S), and bare
  ``owner/repo`` shapes — matching the regex pair in Python's
  ``_get_github_repository_from_env``.
- ``get_github_pull_request_number()`` reads the GitHub event
  payload on GHA and parses ``BUILDKITE_PULL_REQUEST`` (treating
  empty / ``false`` as "no PR") on Buildkite.

Per-command consumption stays narrow: ``scopes_send`` now
delegates to ``detector::get_github_repository`` /
``get_github_pull_request_number`` and only retains the
explicit-flag precedence + error wrapping. Other Python detector
helpers (``get_pipeline_name``, ``get_head_sha``,
``get_cicd_pipeline_run_*``, ``get_base_ref_name``, …) feed
``junit_processing`` and ``ci git-refs`` — neither is ported to
Rust yet, so nothing to mirror until those commands land.

Tests now clear every CI-provider env var the detector inspects
via a shared ``with_ci_env`` helper before applying per-test
overrides, so they no longer inherit provider state from the host
(e.g. Buildkite's own CI). Detector tests cover provider
precedence, repo URL parsing across SSH/HTTPS/bare shapes, and
Buildkite PR resolution edge cases. 26/26 tests green; clippy
clean.

Fixes INC-1357

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: I0fc56c75450b9072380e9f1ea4e83fa01f308f6b
@sileht sileht force-pushed the devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75 branch from a234636 to 54c69c3 Compare May 5, 2026 17:30
@mergify mergify Bot requested a deployment to Mergify Merge Protections May 5, 2026 17:30 In progress
@sileht sileht marked this pull request as ready for review May 5, 2026 17:34
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 5, 2026

Merge Queue Status

  • Entered queue2026-05-05 17:42 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-05 17:43 UTC · at 54c69c377106c5b9d0b639d178a3e470c5206eb0 · squash

This pull request spent 14 seconds in the queue, including 3 seconds running CI.

Required conditions to merge

@mergify mergify Bot merged commit d641cb3 into main May 5, 2026
34 checks passed
@mergify mergify Bot deleted the devs/sileht/buildkite-broken/honor-buildkite-circleci-jenkins-env-ci-scopes--0fc56c75 branch May 5, 2026 17:43
@mergify mergify Bot added queued and removed queued labels May 5, 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