Skip to content
Merged
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
11 changes: 10 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(dir_okay=False),
envvar="MERGIFY_CONFIG_PATH",
default=detector.get_mergify_config_path,
help="Path to YAML config file.",
Comment thread
sileht marked this conversation as resolved.
Comment thread
sileht marked this conversation as resolved.
)
Expand All @@ -242,11 +243,19 @@ def scopes(
head: str | None = None,
base: str | None = None,
) -> None:
# Empty envvar (MERGIFY_CONFIG_PATH="") should fall back to autodetect
if config_path is not None and not config_path:
config_path = detector.get_mergify_config_path()

if config_path is None:
locations = ", ".join(detector.MERGIFY_CONFIG_PATHS)
msg = f"Mergify configuration file not found. Looked in: {locations}"
raise click.ClickException(msg)

if not pathlib.Path(config_path).is_file():
msg = f"Config file '{config_path}' does not exist."
raise click.ClickException(msg)

if base or head:
ref = git_refs_detector.References(
base=base,
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 thread
sileht marked this conversation as resolved.


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