Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 62912d4428 | |||
| 67cf41d721 | |||
| 4ad3761478 |
@@ -8,9 +8,11 @@ import httpx
|
||||
from gql import gql
|
||||
from specklepy.api import operations
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.core.api.models import Branch
|
||||
from specklepy.objects import Base
|
||||
from specklepy.transports.memory import MemoryTransport
|
||||
from specklepy.transports.server import ServerTransport
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
from speckle_automate.schema import (
|
||||
AutomateBase,
|
||||
@@ -118,6 +120,10 @@ class AutomationContext:
|
||||
f" that triggered this automation: {self.automation_run_data.model_id}"
|
||||
)
|
||||
|
||||
branch = self._get_model(model_id)
|
||||
if not branch.name:
|
||||
raise ValueError(f"The model {model_id} has no name.")
|
||||
|
||||
root_object_id = operations.send(
|
||||
root_object,
|
||||
[self._server_transport, self._memory_transport],
|
||||
@@ -131,8 +137,30 @@ class AutomationContext:
|
||||
message=version_message,
|
||||
source_application="SpeckleAutomate",
|
||||
)
|
||||
|
||||
if isinstance(version_id, SpeckleException):
|
||||
raise version_id
|
||||
|
||||
self._automation_result.result_versions.append(version_id)
|
||||
|
||||
def _get_model(self, model_id: str) -> Branch:
|
||||
query = gql(
|
||||
"""
|
||||
query ProjectModel($projectId: String!, $modelId: String!){
|
||||
project(id: $projectId) {
|
||||
model(id: $modelId) {
|
||||
name
|
||||
id
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
params = {"projectId": self.automation_run_data.project_id, "modelId": model_id}
|
||||
response = self.speckle_client.httpclient.execute(query, params)
|
||||
return Branch.model_validate(response["project"]["model"])
|
||||
|
||||
def report_run_status(self) -> None:
|
||||
"""Report the current run status to the project of this automation."""
|
||||
query = gql(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from gql import gql
|
||||
|
||||
@@ -7,6 +7,7 @@ from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
|
||||
from specklepy.core.api.resources.commit import Resource as CoreResource
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
@@ -55,8 +56,8 @@ class Resource(CoreResource):
|
||||
branch_name: str = "main",
|
||||
message: str = "",
|
||||
source_application: str = "python",
|
||||
parents: List[str] = None,
|
||||
) -> str:
|
||||
parents: Optional[List[str]] = None,
|
||||
) -> Union[str, SpeckleException]:
|
||||
"""
|
||||
Creates a commit on a branch
|
||||
|
||||
@@ -76,7 +77,9 @@ class Resource(CoreResource):
|
||||
str -- the id of the created commit
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Commit Create"})
|
||||
return super().create(stream_id, object_id, branch_name, message, source_application, parents)
|
||||
return super().create(
|
||||
stream_id, object_id, branch_name, message, source_application, parents
|
||||
)
|
||||
|
||||
def update(self, stream_id: str, commit_id: str, message: str) -> bool:
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.core.api.models import Commit
|
||||
from specklepy.core.api.resource import ResourceBase
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
NAME = "commit"
|
||||
|
||||
@@ -106,8 +107,8 @@ class Resource(ResourceBase):
|
||||
branch_name: str = "main",
|
||||
message: str = "",
|
||||
source_application: str = "python",
|
||||
parents: List[str] = None,
|
||||
) -> str:
|
||||
parents: Optional[List[str]] = None,
|
||||
) -> Union[str, SpeckleException]:
|
||||
"""
|
||||
Creates a commit on a branch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user