Skip to content

Commit 00da768

Browse files
fix(service): accept commit-sha in config.show (#3685)
1 parent 7a4c9a9 commit 00da768

File tree

5 files changed

+96
-10
lines changed

5 files changed

+96
-10
lines changed

renku/ui/service/controllers/api/mixins.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ def local(self):
183183
raise ProgramRenkuError(error)
184184

185185
project = LocalRepositoryCache().get(
186-
self.cache,
187-
self.request_data["git_url"],
188-
self.request_data.get("branch"),
189-
self.user,
190-
self.clone_depth is not None,
191-
self.request_data.get("commit_sha"),
186+
cache=self.cache,
187+
git_url=self.request_data["git_url"],
188+
branch=self.request_data.get("branch"),
189+
user=self.user,
190+
shallow=self.clone_depth is not None,
191+
commit_sha=self.request_data.get("commit_sha"),
192192
)
193193

194194
self.context["project_id"] = project.project_id

renku/ui/service/controllers/utils/remote_project.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from renku.core import errors
2525
from renku.core.util.contexts import renku_project_context
26-
from renku.infrastructure.repository import Repository
26+
from renku.core.util.git import clone_renku_repository
2727
from renku.ui.service.serializers.cache import ProjectCloneContext
2828
from renku.ui.service.utils import normalize_git_url
2929

@@ -46,6 +46,7 @@ def __init__(self, user_data, request_data):
4646

4747
self.git_url = normalize_git_url(self.ctx["url_with_auth"])
4848
self.branch = self.ctx["branch"]
49+
self.commit_sha = self.ctx["commit_sha"] or ""
4950

5051
@property
5152
def remote_url(self):
@@ -65,7 +66,14 @@ def remote(self):
6566
"""Retrieve project metadata."""
6667
with tempfile.TemporaryDirectory() as td:
6768
try:
68-
Repository.clone_from(self.remote_url.geturl(), td, branch=self.branch, depth=1)
69+
clone_renku_repository(
70+
url=self.remote_url.geturl(),
71+
path=td,
72+
install_lfs=False,
73+
depth=None if self.branch or self.commit_sha else 1,
74+
checkout_revision=self.commit_sha or self.branch,
75+
raise_git_except=True,
76+
)
6977
except errors.GitCommandError as e:
7078
msg = str(e)
7179
if "is not a commit and a branch" in msg and "cannot be created from it" in msg:

renku/ui/service/serializers/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class RepositoryCloneRequest(RemoteRepositorySchema):
132132
"""Request schema for repository clone."""
133133

134134
depth = fields.Integer(metadata={"description": "Git fetch depth"}, load_default=PROJECT_CLONE_DEPTH_DEFAULT)
135+
commit_sha = fields.String(required=False, load_default=None, dump_default=None)
135136

136137

137138
class ProjectCloneContext(RepositoryCloneRequest):

tests/service/fixtures/service_integration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def integration_lifecycle(
9797
it_protected_repo_url,
9898
it_workflow_repo_url,
9999
it_remote_old_repo_url,
100+
it_remote_public_repo_url,
100101
request,
101102
):
102103
"""Setup and teardown steps for integration tests."""
@@ -115,6 +116,8 @@ def integration_lifecycle(
115116
remote_repo = it_workflow_repo_url
116117
elif marker.args[0] == "old":
117118
remote_repo = it_remote_old_repo_url
119+
elif marker.args[0] == "public":
120+
remote_repo = it_remote_public_repo_url
118121
else:
119122
raise ValueError(f"Couldn't get remote repo for marker {marker.args[0]}")
120123

tests/service/views/test_config_views.py

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616
"""Renku service config view tests."""
1717

18+
import configparser
1819
import json
20+
import uuid
1921

2022
import pytest
2123

@@ -43,6 +45,78 @@ def test_config_view_show(svc_client_with_repo):
4345
assert 200 == response.status_code
4446

4547

48+
@pytest.mark.service
49+
@pytest.mark.integration
50+
@retry_failed
51+
@pytest.mark.remote_repo("public")
52+
@pytest.mark.parametrize("anonymous", [False, True])
53+
def test_config_view_show_with_branch(svc_client_setup, anonymous):
54+
"""Check config show view in a different branch."""
55+
svc_client, headers, project_id, url_components, repository = svc_client_setup
56+
57+
if anonymous:
58+
headers = {}
59+
60+
config_filepath = repository.path / ".renku" / "renku.ini"
61+
current_branch = repository.active_branch.name
62+
new_branch = uuid.uuid4().hex
63+
64+
# Write a default config value
65+
config = configparser.ConfigParser()
66+
config.add_section("interactive")
67+
config["interactive"]["default_url"] = "/lab"
68+
config.add_section("renku")
69+
config["renku"]["test-config"] = "current-branch"
70+
with open(config_filepath, "w") as f:
71+
config.write(f)
72+
73+
repository.add(all=True)
74+
repository.commit("master config")
75+
repository.push(remote="origin", refspec=current_branch)
76+
current_commit_sha = repository.active_branch.commit.hexsha
77+
78+
# Create a new branch and a modified config
79+
repository.branches.add(new_branch)
80+
repository.checkout(new_branch)
81+
config["renku"]["test-config"] = "new-branch"
82+
with open(config_filepath, "w") as f:
83+
config.write(f)
84+
85+
repository.add(all=True)
86+
repository.commit("new config")
87+
repository.push(remote="origin", refspec=new_branch)
88+
89+
params = {
90+
"git_url": url_components.href,
91+
"branch": current_branch,
92+
}
93+
94+
response = svc_client.get("/config.show", query_string=params, headers=headers)
95+
96+
assert 200 == response.status_code
97+
assert "current-branch" == response.json["result"]["config"].get("renku.test-config")
98+
99+
params = {
100+
"git_url": url_components.href,
101+
"branch": new_branch,
102+
}
103+
104+
response = svc_client.get("/config.show", query_string=params, headers=headers)
105+
106+
assert 200 == response.status_code
107+
assert "new-branch" == response.json["result"]["config"].get("renku.test-config")
108+
109+
params = {
110+
"git_url": url_components.href,
111+
"branch": current_commit_sha,
112+
}
113+
114+
response = svc_client.get("/config.show", query_string=params, headers=headers)
115+
116+
assert 200 == response.status_code
117+
assert "current-branch" == response.json["result"]["config"].get("renku.test-config")
118+
119+
46120
@pytest.mark.service
47121
@pytest.mark.integration
48122
@retry_failed
@@ -133,7 +207,7 @@ def test_config_view_set(svc_client_with_repo):
133207
@pytest.mark.service
134208
@pytest.mark.integration
135209
@retry_failed
136-
def test_config_view_set_nonexising_key_removal(svc_client_with_repo):
210+
def test_config_view_set_non_existing_key_removal(svc_client_with_repo):
137211
"""Check that removing a non-existing key (i.e. setting to None) is allowed."""
138212
svc_client, headers, project_id, url_components = svc_client_with_repo
139213

@@ -160,7 +234,7 @@ def test_config_view_set_and_show_failures(svc_client_with_repo):
160234
"""Check errors triggered while invoking config set."""
161235
svc_client, headers, project_id, url_components = svc_client_with_repo
162236

163-
# NOTE: use sections with wrong chars introduces a readin error. Should we handle it at write time?
237+
# NOTE: use sections with wrong chars introduces a reading error. Should we handle it at write time?
164238
payload = {
165239
"git_url": url_components.href,
166240
"config": {".NON_EXISTING": "test"},

0 commit comments

Comments
 (0)