Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mergify_cli/ci/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def git_refs() -> None:
@click.option(
"--config",
"config_path",
type=click.Path(),
type=click.Path(exists=True, dir_okay=False),
envvar="MERGIFY_CONFIG_PATH",
default=detector.get_mergify_config_path,
help="Path to YAML config file.",
Comment on lines 218 to 224
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

MERGIFY_CONFIG_PATH set to an empty string will be treated by Click as an explicit option value, and with click.Path(exists=True, dir_okay=False) it will fail parameter validation (exit code 2) before default=get_mergify_config_path can run. This prevents the intended “empty env var => autodetect” behavior (and makes the new test fail). Consider either removing exists=True and validating existence inside scopes() only when a non-empty path is provided, or adding logic to treat an empty envvar value as unset before Click performs path validation.

Copilot uses AI. Check for mistakes.
Comment on lines 218 to 224
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The PR title mentions adding a --config option / MERGIFY_CONFIG_PATH support to both git-refs and scopes, but this diff only updates the scopes command option definition. If git-refs is also meant to accept --config/envvar, that change appears to be missing; otherwise the PR title should be adjusted to match the actual change.

Copilot uses AI. Check for mistakes.
)
Expand Down
19 changes: 19 additions & 0 deletions mergify_cli/tests/ci/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,25 @@ def test_scopes_send(
assert sorted(payload["scopes"]) == ["backend", "foobar", "frontend"]


def test_scopes_empty_mergify_config_env_uses_autodetection(
tmp_path: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""When MERGIFY_CONFIG_PATH is set but empty, the config should be auto-detected."""
config_file = tmp_path / ".mergify.yml"
config_file.write_text("scopes:\n source:\n manual:\n")

monkeypatch.chdir(tmp_path)
monkeypatch.setenv("MERGIFY_CONFIG_PATH", "")

runner = testing.CliRunner()
result = runner.invoke(ci_cli.scopes, ["--base", "old", "--head", "new"])

# The command found the auto-detected config and ran (source is manual so exit 1)
assert result.exit_code == 1
assert "source `manual` has been set" in result.output
Comment on lines +501 to +509
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

This test expects MERGIFY_CONFIG_PATH="" to fall back to config auto-detection and reach the ScopesError path (exit code 1). With the current Click option type set to click.Path(exists=True, dir_okay=False), an empty envvar value is likely to trigger Click’s parameter validation error instead (exit code 2) before the command runs. Either adjust the CLI option handling to treat empty envvar as unset, or change the test to match the actual behavior.

Copilot uses AI. Check for mistakes.


def test_git_refs(
tmp_path: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
Expand Down