Skip to content

Commit

Permalink
swap ref and branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Grubenmann committed Nov 10, 2023
1 parent d5ed339 commit 80f315f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions renku/ui/service/controllers/templates_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def default_metadata(self):

metadata = {
"__template_source__": self.ctx["template_git_url"],
"__template_ref__": self.ctx["branch"],
"__template_ref__": self.ctx["ref"],
"__template_id__": self.ctx["identifier"],
"__namespace__": self.ctx["project_namespace"],
"__repository__": self.ctx["project_repository"],
Expand Down Expand Up @@ -117,7 +117,7 @@ def setup_new_project(self):

def setup_template(self):
"""Reads template manifest."""
templates_source = fetch_templates_source(source=self.ctx["template_git_url"], reference=self.ctx["branch"])
templates_source = fetch_templates_source(source=self.ctx["template_git_url"], reference=self.ctx["ref"])
identifier = self.ctx["identifier"]
try:
self.template = templates_source.get_template(id=identifier, reference=None)
Expand Down
2 changes: 1 addition & 1 deletion renku/ui/service/controllers/templates_read_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def template_manifest(self):
"""Reads template manifest."""
from PIL import Image

templates_source = fetch_templates_source(source=self.ctx["template_git_url"], reference=self.ctx["branch"])
templates_source = fetch_templates_source(source=self.ctx["template_git_url"], reference=self.ctx["ref"])
manifest = templates_source.manifest.get_raw_content()

# NOTE: convert icons to base64
Expand Down
10 changes: 5 additions & 5 deletions renku/ui/service/serializers/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class ManifestTemplatesRequest(Schema):

template_git_url = fields.String(required=True, metadata={"description": "Template git repository url."})
depth = fields.Integer(load_default=TEMPLATE_CLONE_DEPTH_DEFAULT)
branch = fields.String(load_default=None, metadata={"description": "Remote git branch (or tag or commit SHA)."})
ref = fields.String(load_default=None, metadata={"description": "Remote git branch (or tag or commit SHA)."})

@pre_load
def set_fields(self, data, **_):
"""Set `branch` field from `ref` if present and set template url."""
if "ref" in data and not data.get("branch"):
"""Set `ref` field from `branch` if present and set template url."""
if "branch" in data and not data.get("ref"):
# Backward compatibility: branch and ref were both used. Let's keep branch as the exposed field
# even if internally it gets converted to "ref" later.
data["branch"] = data["ref"]
del data["ref"]
data["ref"] = data["branch"]
del data["branch"]
if "url" in data and not data.get("template_git_url"):
# needed for tests that share a fixture
data["template_git_url"] = data["url"]
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def template(template_metadata):
"url": "https://github.com/SwissDataScienceCenter/renku-project-template",
"id": "python-minimal",
"index": 1,
"branch": "master",
"ref": "master",
# TODO: Add template parameters here once parameters are added to the template.
"metadata": {},
"default_metadata": template_metadata,
Expand All @@ -83,15 +83,15 @@ def project_init(template):
"init_custom": [
"init",
"--template-ref",
template["branch"],
template["ref"],
"--template-id",
"python-minimal",
data["test_project"],
],
"init_custom_template": (
"https://gitlab.dev.renku.ch/renku-python-integration-tests/core-it-template-variable-test-project"
),
"remote": ["--template-source", template["url"], "--template-ref", template["branch"]],
"remote": ["--template-source", template["url"], "--template-ref", template["ref"]],
"id": ["--template-id", template["id"]],
"force": ["--force"],
"parameters": ["--parameter", "p1=v1", "--parameter", "p2=v2"],
Expand Down
2 changes: 1 addition & 1 deletion tests/service/controllers/test_templates_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_template_create_project_ctrl(ctrl_init, svc_client_templates_creation,
"template_git_url",
"project_name_stripped",
"depth",
"branch",
"ref",
"new_project_url_with_auth",
}
assert expected_context.issubset(set(ctrl.context.keys()))
Expand Down

0 comments on commit 80f315f

Please sign in to comment.