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
9 changes: 8 additions & 1 deletion datajunction-clients/python/datajunction/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,18 @@ def get_impact(
"""
console = console or self.console
deployment_spec, file_errors = self._reconstruct_deployment_spec(source_path)
deployment_spec["namespace"] = namespace or deployment_spec.get("namespace")
base_namespace = deployment_spec.get("namespace") or ""
source = deployment_spec.get("source", {})
branch = os.getenv("DJ_DEPLOY_BRANCH") or DeploymentService._detect_git_branch(
cwd=source_path,
)
if namespace:
deployment_spec["namespace"] = namespace
elif branch and base_namespace:
deployment_spec["namespace"] = DeploymentService._derive_namespace(
base_namespace,
branch,
)
if display:
print_deployment_header(
mode="dry run",
Expand Down
2 changes: 2 additions & 0 deletions datajunction-clients/python/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,8 @@ def test_push_with_repo_flag_sets_env_var(
"dj",
"push",
"./deploy0",
"--namespace",
"repo_flag_test",
"--repo",
"github.com/test/repo",
]
Expand Down
29 changes: 29 additions & 0 deletions datajunction-clients/python/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,35 @@ def test_get_impact_with_namespace_override(self, tmp_path, monkeypatch):
call_args = mock_client.get_deployment_impact.call_args[0][0]
assert call_args["namespace"] == "override.ns"

def test_get_impact_derives_namespace_from_git_branch(self, tmp_path, monkeypatch):
"""get_impact should derive namespace from git branch, same as push."""
(tmp_path / "dj.yaml").write_text(yaml.safe_dump({"namespace": "project"}))
(tmp_path / "my_node.yaml").write_text(
yaml.safe_dump({"name": "project.my_node"}),
)

monkeypatch.delenv("DJ_DEPLOY_REPO", raising=False)
monkeypatch.delenv("DJ_DEPLOY_BRANCH", raising=False)
monkeypatch.setattr(
"datajunction.deployment.subprocess.run",
lambda *a, **kw: mock.MagicMock(stdout="feature/new-metric\n"),
)

mock_client = MagicMock()
mock_client.get_deployment_impact.return_value = {
"uuid": "dry_run",
"namespace": "project.feature_new_metric",
"status": "success",
"results": [],
"downstream_impacts": [],
}

svc = DeploymentService(mock_client, console=Console(file=io.StringIO()))
svc.get_impact(tmp_path)

call_args = mock_client.get_deployment_impact.call_args[0][0]
assert call_args["namespace"] == "project.feature_new_metric"


class TestDetectGitBranch:
"""Tests for _detect_git_branch."""
Expand Down
Loading