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
5 changes: 4 additions & 1 deletion mergify_cli/ci/scopes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def detect(config_path: str) -> DetectedScope:
per_scope: dict[str, list[str]]

source = cfg.scopes.source
if source is None or isinstance(source, config.SourceManual):
if source is None:
all_scopes = set()
scopes_hit = set()
per_scope = {}
Expand All @@ -139,6 +139,9 @@ def detect(config_path: str) -> DetectedScope:
click.echo(f"- {file}")
all_scopes = set(source.files.keys())
scopes_hit, per_scope = match_scopes(changed, source.files)
elif isinstance(source, config.SourceManual):
msg = "source `manual` has been set, scopes must be sent with `scopes-send` or API"
raise exceptions.ScopesError(msg)
else:
msg = "Unsupported source type" # type:ignore[unreachable]
raise RuntimeError(msg)
Expand Down
19 changes: 7 additions & 12 deletions mergify_cli/tests/ci/scopes/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from mergify_cli.ci.git_refs import detector
from mergify_cli.ci.scopes import cli
from mergify_cli.ci.scopes import config
from mergify_cli.ci.scopes import exceptions


if TYPE_CHECKING:
Expand Down Expand Up @@ -398,7 +399,7 @@ def test_detect_manual(
) -> None:
# Setup config file
config_data = {
"scopes": {"source": None},
"scopes": {"source": {"manual": None}},
}
config_file = tmp_path / ".mergify-ci.yml"
config_file.write_text(yaml.dump(config_data))
Expand All @@ -411,17 +412,11 @@ def test_detect_manual(
)

# Capture output
with mock.patch("click.echo") as mock_echo:
result = cli.detect(str(config_file))

# Verify output
calls = [call.args[0] for call in mock_echo.call_args_list]
assert "Base: old" in calls
assert "Head: new" in calls
assert "No scopes matched." in calls
assert result.scopes == set()
assert result.base_ref == "old"
assert result.head_ref == "new"
with pytest.raises(
exceptions.ScopesError,
match="source `manual` has been set, scopes must be sent with `scopes-send` or API",
):
cli.detect(str(config_file))


@mock.patch("mergify_cli.ci.git_refs.detector.detect")
Expand Down