Skip to content

Commit

Permalink
allow querying project information by project ID (fix #179)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 10, 2023
1 parent 6d60827 commit 30ab43c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def projects_list(
break
return projects

def project_info(self, project_path, since=None, version=None):
def project_info(self, project_path_or_id, since=None, version=None):
"""
Fetch info about project.
Expand All @@ -639,7 +639,11 @@ def project_info(self, project_path, since=None, version=None):
# since and version are mutually exclusive
if version:
params = {"version": version}
resp = self.get("/v1/project/{}".format(project_path), params)

if re.match("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", project_path_or_id):
resp = self.get("/v1/project/by_uuid/{}".format(project_path_or_id), params)
else:
resp = self.get("/v1/project/{}".format(project_path_or_id), params)
return json.load(resp)

def project_versions(self, project_path, since=None, to=None):
Expand Down
7 changes: 7 additions & 0 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ def test_create_remote_project_from_local(mc):
assert project_info["namespace"] == API_USER
assert project_info["id"] == source_mp.project_id()

# check project metadata retrieval by id
project_info = mc.project_info(source_mp.project_id())
assert project_info["version"] == "v1"
assert project_info["name"] == test_project
assert project_info["namespace"] == API_USER
assert project_info["id"] == source_mp.project_id()

versions = mc.project_versions(project)
assert len(versions) == 1
assert versions[0]["name"] == "v1"
Expand Down

0 comments on commit 30ab43c

Please sign in to comment.