Skip to content

Commit 3800a38

Browse files
authored
fix(service): add branch to service cache path (#3562)
1 parent 6f0e24d commit 3800a38

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

renku/ui/service/cache/models/project.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
MAX_CONCURRENT_PROJECT_REQUESTS = 10
3131
LOCK_TIMEOUT = 15
32+
NO_BRANCH_FOLDER = "__default_branch__"
3233

3334

3435
class Project(Model):
@@ -57,7 +58,10 @@ class Project(Model):
5758
@property
5859
def abs_path(self) -> Path:
5960
"""Full path of cached project."""
60-
return CACHE_PROJECTS_PATH / self.user_id / self.owner / self.slug
61+
branch = self.branch
62+
if not self.branch:
63+
branch = NO_BRANCH_FOLDER
64+
return CACHE_PROJECTS_PATH / self.user_id / self.owner / self.slug / branch
6165

6266
def read_lock(self, timeout: Optional[float] = None):
6367
"""Shared read lock on the project."""

renku/ui/service/utils/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""Renku service utility functions."""
1818

1919
from renku.core.util.git import push_changes
20+
from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER
2021
from renku.ui.service.config import CACHE_PROJECTS_PATH, CACHE_UPLOADS_PATH
2122

2223

@@ -26,7 +27,13 @@ def make_project_path(user, project):
2627
valid_project = project and "owner" in project and "name" in project and "project_id" in project
2728

2829
if valid_user and valid_project:
29-
return CACHE_PROJECTS_PATH / user["user_id"] / project["owner"] / project["slug"]
30+
return (
31+
CACHE_PROJECTS_PATH
32+
/ user["user_id"]
33+
/ project["owner"]
34+
/ project["slug"]
35+
/ project.get("branch", NO_BRANCH_FOLDER)
36+
)
3037

3138

3239
def make_file_path(user, cached_file):

tests/service/controllers/test_templates_create_project.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_template_create_project_ctrl(ctrl_init, svc_client_templates_creation,
3939

4040
# Check ctrl_mock.
4141
assert ctrl_mock.call_count == 1
42-
assert response.json["result"]["slug"] == ctrl_mock.call_args[0][0].name
42+
assert response.json["result"]["slug"] == ctrl_mock.call_args[0][0].parent.name
4343

4444
# Ctrl state.
4545
expected_context = {
@@ -165,6 +165,8 @@ def test_template_create_project_with_custom_cli_ctrl(
165165
ctrl_init, svc_cache_dir, svc_client_templates_creation, mocker, monkeypatch
166166
):
167167
"""Test template create project controller."""
168+
from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER
169+
168170
monkeypatch.setenv("RENKU_PROJECT_DEFAULT_CLI_VERSION", "9.9.9rc9")
169171
from renku.ui.service.controllers.templates_create_project import TemplatesCreateProjectCtrl
170172

@@ -182,7 +184,11 @@ def test_template_create_project_with_custom_cli_ctrl(
182184
cache_dir, _ = svc_cache_dir
183185

184186
project_path = (
185-
cache_dir / user_data["user_id"] / response.json["result"]["namespace"] / response.json["result"]["slug"]
187+
cache_dir
188+
/ user_data["user_id"]
189+
/ response.json["result"]["namespace"]
190+
/ response.json["result"]["slug"]
191+
/ NO_BRANCH_FOLDER
186192
)
187193

188194
with open(project_path / "Dockerfile") as f:

tests/service/views/test_templates_views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_read_manifest_from_wrong_template(svc_client_with_templates, template_u
124124
@retry_failed
125125
def test_create_project_from_template(svc_client_templates_creation, with_injection):
126126
"""Check creating project from a valid template."""
127+
from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER
127128
from renku.ui.service.serializers.headers import RenkuHeaders
128129
from renku.ui.service.utils import CACHE_PROJECTS_PATH
129130

@@ -142,7 +143,9 @@ def test_create_project_from_template(svc_client_templates_creation, with_inject
142143

143144
# NOTE: assert correct git user is set on new project
144145
user_data = RenkuHeaders.decode_user(headers["Renku-User"])
145-
project_path = CACHE_PROJECTS_PATH / user_data["user_id"] / payload["project_namespace"] / stripped_name
146+
project_path = (
147+
CACHE_PROJECTS_PATH / user_data["user_id"] / payload["project_namespace"] / stripped_name / NO_BRANCH_FOLDER
148+
)
146149
reader = Repository(project_path).get_configuration()
147150
assert reader.get_value("user", "email") == user_data["email"]
148151
assert reader.get_value("user", "name") == user_data["name"]

0 commit comments

Comments
 (0)