Skip to content

feat(ci-insights): Add mergify tests show command#1382

Open
remyduthu wants to merge 1 commit into
mainfrom
devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649
Open

feat(ci-insights): Add mergify tests show command#1382
remyduthu wants to merge 1 commit into
mainfrom
devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649

Conversation

@remyduthu
Copy link
Copy Markdown
Contributor

@remyduthu remyduthu commented May 6, 2026

Wraps two CI Insights endpoints into a single batch command:

  • GET /v1/ci/{owner}/repositories/{repo}/search/tests resolves test
    identities by name (glob-aware) on the default branch. Filters
    (test_name, pipeline_name, job_name, …) travel as repeated
    query parameters; page size travels as per_page.
  • GET /v1/ci/{owner}/repositories/{repo}/tests/{test_id} returns the
    full health/metrics payload for one identity.

The search is a true batch API — pass one or more <NAME> positionals
(globs allowed) and one block per match is rendered. --json emits a
single {"tests": [...]} document; the human renderer hides metadata
lines for absent fields rather than printing placeholders. Exit code
reflects the worst health observed across results (0 = healthy or
unknown, 1 = any flaky, 6 = any broken).

Token and API URL resolution moved from scopes_send.rs into a new
common.rs so every Mergify-targeting ci subcommand shares the same
explicit-flag → env-var → default fallback chain. split_owner_repo
moved into detector.rs next to the existing owner/repo validators.
A new HttpClient::get_with_query helper percent-encodes values and
preserves repeated keys in caller order, which the search endpoint
relies on for test_name repetition.

Also adds a live-smoke case that exercises the search endpoint with a
guaranteed-nonexistent name so the round-trip stays independent of
canary repository state.

Fixes: MRGFY-7166

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

Copilot AI review requested due to automatic review settings May 6, 2026 13:56
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 6, 2026 13:56 Failure
@remyduthu remyduthu self-assigned this May 6, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 6, 2026

Merge Protections

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

🔴 👀 Review Requirements

Waiting for

  • #approved-reviews-by>=2
This rule is failing.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🔴 🔎 Reviews

Waiting for

  • #review-requested = 0
  • #review-threads-unresolved = 0
This rule is failing.
  • #review-requested = 0
  • #review-threads-unresolved = 0
  • #changes-requested-reviews-by = 0

🟢 🤖 Continuous Integration

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

🟢 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)(?:\(.+\))?:

🟢 📕 PR description

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

@remyduthu remyduthu changed the title feat(rust): Add mergify ci tests lookup command feat(ci-insights): Add mergify ci tests lookup command May 6, 2026
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 6544154 to 57267f7 Compare May 6, 2026 13:56
@remyduthu
Copy link
Copy Markdown
Contributor Author

remyduthu commented May 6, 2026

Revision history

# Type Changes Reason Date
1 initial 6544154 2026-05-06 13:56 UTC
2 rebase 6544154 → 57267f7 2026-05-06 13:56 UTC
3 content 57267f7 → 3d1d1d8 2026-05-06 14:38 UTC
4 content 3d1d1d8 → 10479a6 2026-05-20 09:39 UTC
5 content 10479a6 → 51d9b34 (raw) 2026-05-20 10:01 UTC
6 content 51d9b34 → 099fc3a (raw) 2026-05-20 10:20 UTC
7 content 099fc3a → 7a3a0d2 2026-05-20 13:38 UTC
8 rebase 7a3a0d2 → 93627c6 (rebase only) 2026-05-20 13:39 UTC
9 content 93627c6 → a42941c (raw) 2026-05-20 15:11 UTC
10 content a42941c → fb35e47 (raw) 2026-05-20 15:16 UTC

@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 6, 2026 13:57 Failure
@remyduthu remyduthu marked this pull request as ready for review May 6, 2026 14:00
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

Adds a new native Rust mergify ci tests lookup command to batch-resolve CI Insights test identities by name (glob-aware), fetch per-test health/metrics, and render either human output or a single JSON payload. This extends the Rust-native mergify ci surface area and introduces a reusable HTTP helper for ordered/repeated query parameters.

Changes:

  • Add mergify ci tests lookup NAME... command (CLI wiring, API calls, rendering, exit-code aggregation, and unit tests).
  • Add HttpClient::get_with_query to support ordered/repeated query params with proper encoding.
  • Update docs and add a live smoke test exercising the lookup endpoint.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
skills/mergify-ci/SKILL.md Documents the new ci tests lookup command, options, and exit codes.
README.md Mentions test health inspection under the mergify ci command group.
func-tests/test_live_smoke.py Adds a live smoke test for the lookup endpoint (no-match path).
crates/mergify-core/src/http.rs Introduces get_with_query plus unit tests for ordering/encoding behavior.
crates/mergify-cli/src/main.rs Adds clap subcommand plumbing + native dispatch for ci tests lookup and JSON mode selection.
crates/mergify-ci/src/tests_lookup.rs Implements lookup + details fan-out, rendering, JSON payload, exit code policy, and tests.
crates/mergify-ci/src/lib.rs Exposes the new tests_lookup module.
crates/mergify-ci/src/detector.rs Adds split_owner_repo helper with tests.
crates/mergify-ci/Cargo.toml Adds Rust deps needed by the new command (chrono, futures).
Cargo.lock Lockfile updates for newly introduced/updated dependencies.

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

Comment thread crates/mergify-ci/src/detector.rs Outdated
Comment thread crates/mergify-cli/src/main.rs
Comment thread func-tests/test_live_smoke.py
@mergify mergify Bot requested a review from a team May 6, 2026 14:10
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 57267f7 to 3d1d1d8 Compare May 6, 2026 14:38
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 6, 2026 14:39 Failure
@remyduthu remyduthu marked this pull request as draft May 18, 2026 13:31
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 18, 2026

@remyduthu this pull request is now in conflict 😩

@mergify mergify Bot added the conflict label May 18, 2026
Comment thread crates/mergify-ci/src/tests_show.rs
@remyduthu remyduthu changed the title feat(ci-insights): Add mergify ci tests lookup command feat(ci-insights): Add mergify ci tests show command May 20, 2026
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 3d1d1d8 to 10479a6 Compare May 20, 2026 09:39
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 09:39 — with GitHub Actions Inactive
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 09:39 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 09:39 Failure
@mergify mergify Bot removed the conflict label May 20, 2026
@remyduthu
Copy link
Copy Markdown
Contributor Author

Code review

Found 1 issue:

  1. ci tests show declares --repository as required = true and passes the raw String straight to tests_show::run, so it bypasses the mergify_core::auth::resolve_repository fallback chain (--repository flag → GITHUB_REPOSITORY env → git config remote.origin.url) that every other ported native command honors. The result is that this one command refuses to run in CI even when the surrounding environment already names the repository.

    New flag and dispatch:

    /// Repository full name (owner/repo).
    #[arg(long, short = 'r', required = true)]
    repository: String,
    /// Mergify or GitHub token. Falls back to ``MERGIFY_TOKEN`` and
    /// then ``GITHUB_TOKEN`` env vars.

    NativeCommand::CiTestsShow(opts) => {
    mergify_ci::tests_show::run(
    TestsShowOptions {
    repository: &opts.repository,
    test_names: &opts.test_names,
    token: opts.token.as_deref(),
    api_url: opts.api_url.as_deref(),
    pipeline_name: &opts.pipeline_name,
    pipeline_name_exclude: &opts.pipeline_name_exclude,
    job_name: &opts.job_name,
    job_name_exclude: &opts.job_name_exclude,

    Sibling pattern (Option<String> + .as_deref(), then the sub-crate calls resolve_repository):

    struct CiScopesSendOpts {
    repository: Option<String>,
    pull_request: Option<u64>,
    token: Option<String>,
    api_url: Option<String>,
    scopes: Vec<String>,
    scopes_json: Option<PathBuf>,
    scopes_file: Option<PathBuf>,
    file_deprecated: Option<PathBuf>,

    NativeCommand::QueuePause(opts) => {
    mergify_queue::pause::run(
    PauseOptions {
    repository: opts.repository.as_deref(),
    token: opts.token.as_deref(),
    api_url: opts.api_url.as_deref(),
    reason: &opts.reason,
    yes_i_am_sure: opts.yes_i_am_sure,
    },
    &mut output,
    )
    .await
    .map(|()| mergify_core::ExitCode::Success)
    }
    NativeCommand::QueueUnpause(opts) => {

    Existing helper that should be used:

    /// Resolve the repository (`<owner>/<repo>`).
    ///
    /// Precedence: explicit `--repository`, then `GITHUB_REPOSITORY`
    /// env, then `git config --get remote.origin.url` parsed via
    /// [`parse_slug`]. Errors when none of those yield a slug.
    pub fn resolve_repository(explicit: Option<&str>) -> Result<String, CliError> {
    if let Some(value) = explicit.filter(|s| !s.is_empty()) {
    return Ok(value.to_string());
    }
    if let Ok(value) = env::var("GITHUB_REPOSITORY") {
    if !value.is_empty() {
    return Ok(value);
    }
    }
    if let Some(remote) = git_remote_origin_url() {
    if let Some(slug) = parse_slug(&remote) {
    return Ok(slug);
    }
    }
    Err(CliError::Configuration(
    "--repository not provided, GITHUB_REPOSITORY env var is unset, and \
    the local git config has no usable `remote.origin.url`"
    .to_string(),
    ))
    }

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 51d9b34 to 099fc3a Compare May 20, 2026 10:20
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 10:20 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 10:20 Failure
Comment thread crates/mergify-cli/src/main.rs Outdated
@mergify mergify Bot requested a review from a team May 20, 2026 11:31
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 099fc3a to 7a3a0d2 Compare May 20, 2026 13:38
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 13:38 — with GitHub Actions Inactive
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 13:38 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 13:39 Failure
@remyduthu remyduthu changed the title feat(ci-insights): Add mergify ci tests show command feat(ci-insights): Add mergify tests show command May 20, 2026
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 7a3a0d2 to 93627c6 Compare May 20, 2026 13:39
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 13:39 — with GitHub Actions Inactive
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 13:39 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 13:39 Failure
Comment thread crates/mergify-ci/Cargo.toml Outdated

[dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock", "serde", "std"] }
futures = { version = "0.3", default-features = false, features = ["std"] }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair question — and on a second look the dep wasn't earning its slot. Dropped in fb35e47: fetch_all_details now uses tokio::task::JoinSet (rt feature only, no new top-level crate) for the same bounded fan-out (5 concurrent detail fetches, input order preserved). Clean rebuild no longer compiles the futures meta crate or its -executor/-macro/-sink/-io siblings.

@mergify mergify Bot requested a review from a team May 20, 2026 13:59
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from 93627c6 to a42941c Compare May 20, 2026 15:11
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 15:11 — with GitHub Actions Inactive
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 15:11 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 15:11 Failure
Wraps two CI Insights endpoints into a single batch command:

- `GET /v1/ci/{owner}/repositories/{repo}/search/tests` resolves test
  identities by name (glob-aware) on the default branch. Filters
  (`test_name`, `pipeline_name`, `job_name`, …) travel as repeated
  query parameters; page size travels as `per_page`.
- `GET /v1/ci/{owner}/repositories/{repo}/tests/{test_id}` returns the
  full health/metrics payload for one identity.

The search is a true batch API — pass one or more `<NAME>` positionals
(globs allowed) and one block per match is rendered. `--json` emits a
single `{"tests": [...]}` document; the human renderer hides metadata
lines for absent fields rather than printing placeholders. Exit code
reflects the worst health observed across results (0 = healthy or
unknown, 1 = any flaky, 6 = any broken).

Token and API URL resolution moved from `scopes_send.rs` into a new
`common.rs` so every Mergify-targeting `ci` subcommand shares the same
explicit-flag → env-var → default fallback chain. `split_owner_repo`
moved into `detector.rs` next to the existing `owner/repo` validators.
A new `HttpClient::get_with_query` helper percent-encodes values and
preserves repeated keys in caller order, which the search endpoint
relies on for `test_name` repetition.

Also adds a live-smoke case that exercises the search endpoint with a
guaranteed-nonexistent name so the round-trip stays independent of
canary repository state.

Fixes: MRGFY-7166

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: Iafe286495b7842079e9c63b437a6305926fc22a5
@remyduthu remyduthu force-pushed the devs/remyduthu/tests-lookup-cli/add-mergify-ci-tests-lookup-cmd--afe28649 branch from a42941c to fb35e47 Compare May 20, 2026 15:16
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 15:16 — with GitHub Actions Inactive
@remyduthu remyduthu temporarily deployed to func-tests-live May 20, 2026 15:16 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 20, 2026 15:16 Failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants