Skip to content

Commit edc85bd

Browse files
feat(api): add endpoint to retrieve commit by id (#421)
1 parent c213f92 commit edc85bd

File tree

6 files changed

+309
-1
lines changed

6 files changed

+309
-1
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 14
1+
configured_endpoints: 15

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ Methods:
3939

4040
# Commits
4141

42+
Types:
43+
44+
```python
45+
from openlayer.types import CommitRetrieveResponse
46+
```
47+
48+
Methods:
49+
50+
- <code title="get /versions/{projectVersionId}">client.commits.<a href="./src/openlayer/resources/commits/commits.py">retrieve</a>(project_version_id) -> <a href="./src/openlayer/types/commit_retrieve_response.py">CommitRetrieveResponse</a></code>
51+
4252
## TestResults
4353

4454
Types:

src/openlayer/resources/commits/commits.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
from __future__ import annotations
44

5+
import httpx
6+
7+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
58
from ..._compat import cached_property
69
from ..._resource import SyncAPIResource, AsyncAPIResource
10+
from ..._response import (
11+
to_raw_response_wrapper,
12+
to_streamed_response_wrapper,
13+
async_to_raw_response_wrapper,
14+
async_to_streamed_response_wrapper,
15+
)
716
from .test_results import (
817
TestResultsResource,
918
AsyncTestResultsResource,
@@ -12,6 +21,8 @@
1221
TestResultsResourceWithStreamingResponse,
1322
AsyncTestResultsResourceWithStreamingResponse,
1423
)
24+
from ..._base_client import make_request_options
25+
from ...types.commit_retrieve_response import CommitRetrieveResponse
1526

1627
__all__ = ["CommitsResource", "AsyncCommitsResource"]
1728

@@ -40,6 +51,39 @@ def with_streaming_response(self) -> CommitsResourceWithStreamingResponse:
4051
"""
4152
return CommitsResourceWithStreamingResponse(self)
4253

54+
def retrieve(
55+
self,
56+
project_version_id: str,
57+
*,
58+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
59+
# The extra values given here take precedence over values defined on the client or passed to this method.
60+
extra_headers: Headers | None = None,
61+
extra_query: Query | None = None,
62+
extra_body: Body | None = None,
63+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
64+
) -> CommitRetrieveResponse:
65+
"""
66+
Retrieve a project version (commit) by its id.
67+
68+
Args:
69+
extra_headers: Send extra headers
70+
71+
extra_query: Add additional query parameters to the request
72+
73+
extra_body: Add additional JSON properties to the request
74+
75+
timeout: Override the client-level default timeout for this request, in seconds
76+
"""
77+
if not project_version_id:
78+
raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}")
79+
return self._get(
80+
f"/versions/{project_version_id}",
81+
options=make_request_options(
82+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
83+
),
84+
cast_to=CommitRetrieveResponse,
85+
)
86+
4387

4488
class AsyncCommitsResource(AsyncAPIResource):
4589
@cached_property
@@ -65,11 +109,48 @@ def with_streaming_response(self) -> AsyncCommitsResourceWithStreamingResponse:
65109
"""
66110
return AsyncCommitsResourceWithStreamingResponse(self)
67111

112+
async def retrieve(
113+
self,
114+
project_version_id: str,
115+
*,
116+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
117+
# The extra values given here take precedence over values defined on the client or passed to this method.
118+
extra_headers: Headers | None = None,
119+
extra_query: Query | None = None,
120+
extra_body: Body | None = None,
121+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
122+
) -> CommitRetrieveResponse:
123+
"""
124+
Retrieve a project version (commit) by its id.
125+
126+
Args:
127+
extra_headers: Send extra headers
128+
129+
extra_query: Add additional query parameters to the request
130+
131+
extra_body: Add additional JSON properties to the request
132+
133+
timeout: Override the client-level default timeout for this request, in seconds
134+
"""
135+
if not project_version_id:
136+
raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}")
137+
return await self._get(
138+
f"/versions/{project_version_id}",
139+
options=make_request_options(
140+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
141+
),
142+
cast_to=CommitRetrieveResponse,
143+
)
144+
68145

69146
class CommitsResourceWithRawResponse:
70147
def __init__(self, commits: CommitsResource) -> None:
71148
self._commits = commits
72149

150+
self.retrieve = to_raw_response_wrapper(
151+
commits.retrieve,
152+
)
153+
73154
@cached_property
74155
def test_results(self) -> TestResultsResourceWithRawResponse:
75156
return TestResultsResourceWithRawResponse(self._commits.test_results)
@@ -79,6 +160,10 @@ class AsyncCommitsResourceWithRawResponse:
79160
def __init__(self, commits: AsyncCommitsResource) -> None:
80161
self._commits = commits
81162

163+
self.retrieve = async_to_raw_response_wrapper(
164+
commits.retrieve,
165+
)
166+
82167
@cached_property
83168
def test_results(self) -> AsyncTestResultsResourceWithRawResponse:
84169
return AsyncTestResultsResourceWithRawResponse(self._commits.test_results)
@@ -88,6 +173,10 @@ class CommitsResourceWithStreamingResponse:
88173
def __init__(self, commits: CommitsResource) -> None:
89174
self._commits = commits
90175

176+
self.retrieve = to_streamed_response_wrapper(
177+
commits.retrieve,
178+
)
179+
91180
@cached_property
92181
def test_results(self) -> TestResultsResourceWithStreamingResponse:
93182
return TestResultsResourceWithStreamingResponse(self._commits.test_results)
@@ -97,6 +186,10 @@ class AsyncCommitsResourceWithStreamingResponse:
97186
def __init__(self, commits: AsyncCommitsResource) -> None:
98187
self._commits = commits
99188

189+
self.retrieve = async_to_streamed_response_wrapper(
190+
commits.retrieve,
191+
)
192+
100193
@cached_property
101194
def test_results(self) -> AsyncTestResultsResourceWithStreamingResponse:
102195
return AsyncTestResultsResourceWithStreamingResponse(self._commits.test_results)

src/openlayer/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .project_create_params import ProjectCreateParams as ProjectCreateParams
77
from .project_list_response import ProjectListResponse as ProjectListResponse
88
from .project_create_response import ProjectCreateResponse as ProjectCreateResponse
9+
from .commit_retrieve_response import CommitRetrieveResponse as CommitRetrieveResponse
910
from .inference_pipeline_update_params import InferencePipelineUpdateParams as InferencePipelineUpdateParams
1011
from .inference_pipeline_retrieve_params import InferencePipelineRetrieveParams as InferencePipelineRetrieveParams
1112
from .inference_pipeline_update_response import InferencePipelineUpdateResponse as InferencePipelineUpdateResponse
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from datetime import datetime
5+
from typing_extensions import Literal
6+
7+
from pydantic import Field as FieldInfo
8+
9+
from .._models import BaseModel
10+
11+
__all__ = ["CommitRetrieveResponse", "Commit", "Links"]
12+
13+
14+
class Commit(BaseModel):
15+
id: str
16+
"""The commit id."""
17+
18+
author_id: str = FieldInfo(alias="authorId")
19+
"""The author id of the commit."""
20+
21+
file_size: Optional[int] = FieldInfo(alias="fileSize", default=None)
22+
"""The size of the commit bundle in bytes."""
23+
24+
message: str
25+
"""The commit message."""
26+
27+
ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None)
28+
"""The model id."""
29+
30+
storage_uri: str = FieldInfo(alias="storageUri")
31+
"""The storage URI where the commit bundle is stored."""
32+
33+
training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None)
34+
"""The training dataset id."""
35+
36+
validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None)
37+
"""The validation dataset id."""
38+
39+
date_created: Optional[datetime] = FieldInfo(alias="dateCreated", default=None)
40+
"""The commit creation date."""
41+
42+
git_commit_ref: Optional[str] = FieldInfo(alias="gitCommitRef", default=None)
43+
"""The ref of the corresponding git commit."""
44+
45+
git_commit_sha: Optional[int] = FieldInfo(alias="gitCommitSha", default=None)
46+
"""The SHA of the corresponding git commit."""
47+
48+
git_commit_url: Optional[str] = FieldInfo(alias="gitCommitUrl", default=None)
49+
"""The URL of the corresponding git commit."""
50+
51+
52+
class Links(BaseModel):
53+
app: str
54+
55+
56+
class CommitRetrieveResponse(BaseModel):
57+
id: str
58+
"""The project version (commit) id."""
59+
60+
commit: Commit
61+
"""The details of a commit (project version)."""
62+
63+
date_archived: Optional[datetime] = FieldInfo(alias="dateArchived", default=None)
64+
"""The commit archive date."""
65+
66+
date_created: datetime = FieldInfo(alias="dateCreated")
67+
"""The project version (commit) creation date."""
68+
69+
failing_goal_count: int = FieldInfo(alias="failingGoalCount")
70+
"""The number of tests that are failing for the commit."""
71+
72+
ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None)
73+
"""The model id."""
74+
75+
passing_goal_count: int = FieldInfo(alias="passingGoalCount")
76+
"""The number of tests that are passing for the commit."""
77+
78+
project_id: str = FieldInfo(alias="projectId")
79+
"""The project id."""
80+
81+
status: Literal["queued", "running", "paused", "failed", "completed", "unknown"]
82+
"""The commit status.
83+
84+
Initially, the commit is `queued`, then, it switches to `running`. Finally, it
85+
can be `paused`, `failed`, or `completed`.
86+
"""
87+
88+
status_message: Optional[str] = FieldInfo(alias="statusMessage", default=None)
89+
"""The commit status message."""
90+
91+
total_goal_count: int = FieldInfo(alias="totalGoalCount")
92+
"""The total number of tests for the commit."""
93+
94+
training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None)
95+
"""The training dataset id."""
96+
97+
validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None)
98+
"""The validation dataset id."""
99+
100+
archived: Optional[bool] = None
101+
"""Whether the commit is archived."""
102+
103+
deployment_status: Optional[str] = FieldInfo(alias="deploymentStatus", default=None)
104+
"""The deployment status associated with the commit's model."""
105+
106+
links: Optional[Links] = None

tests/api_resources/test_commits.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
import os
6+
from typing import Any, cast
7+
8+
import pytest
9+
10+
from openlayer import Openlayer, AsyncOpenlayer
11+
from tests.utils import assert_matches_type
12+
from openlayer.types import CommitRetrieveResponse
13+
14+
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15+
16+
17+
class TestCommits:
18+
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19+
20+
@parametrize
21+
def test_method_retrieve(self, client: Openlayer) -> None:
22+
commit = client.commits.retrieve(
23+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
24+
)
25+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
26+
27+
@parametrize
28+
def test_raw_response_retrieve(self, client: Openlayer) -> None:
29+
response = client.commits.with_raw_response.retrieve(
30+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
31+
)
32+
33+
assert response.is_closed is True
34+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
35+
commit = response.parse()
36+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
37+
38+
@parametrize
39+
def test_streaming_response_retrieve(self, client: Openlayer) -> None:
40+
with client.commits.with_streaming_response.retrieve(
41+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
42+
) as response:
43+
assert not response.is_closed
44+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
45+
46+
commit = response.parse()
47+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
48+
49+
assert cast(Any, response.is_closed) is True
50+
51+
@parametrize
52+
def test_path_params_retrieve(self, client: Openlayer) -> None:
53+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_version_id` but received ''"):
54+
client.commits.with_raw_response.retrieve(
55+
"",
56+
)
57+
58+
59+
class TestAsyncCommits:
60+
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
61+
62+
@parametrize
63+
async def test_method_retrieve(self, async_client: AsyncOpenlayer) -> None:
64+
commit = await async_client.commits.retrieve(
65+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
66+
)
67+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
68+
69+
@parametrize
70+
async def test_raw_response_retrieve(self, async_client: AsyncOpenlayer) -> None:
71+
response = await async_client.commits.with_raw_response.retrieve(
72+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
73+
)
74+
75+
assert response.is_closed is True
76+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
77+
commit = await response.parse()
78+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
79+
80+
@parametrize
81+
async def test_streaming_response_retrieve(self, async_client: AsyncOpenlayer) -> None:
82+
async with async_client.commits.with_streaming_response.retrieve(
83+
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
84+
) as response:
85+
assert not response.is_closed
86+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
87+
88+
commit = await response.parse()
89+
assert_matches_type(CommitRetrieveResponse, commit, path=["response"])
90+
91+
assert cast(Any, response.is_closed) is True
92+
93+
@parametrize
94+
async def test_path_params_retrieve(self, async_client: AsyncOpenlayer) -> None:
95+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_version_id` but received ''"):
96+
await async_client.commits.with_raw_response.retrieve(
97+
"",
98+
)

0 commit comments

Comments
 (0)