Skip to content

Commit 141bcd4

Browse files
feat(api): add resource_type_filters parameter to events watch method
1 parent 0eb24b8 commit 141bcd4

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 175
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-0ce6b31b2b602e71c429c0a3b6badb639c6a8efdda66ae724abaf57cdd279429.yml
3-
openapi_spec_hash: 36b42ad4f9be97ce27e8d2243a3f9e1c
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-1968882466818a42e20c78ead4d7565ffb92872416a570e5d6a2f9e2cf024e58.yml
3+
openapi_spec_hash: 510d568d2b22bcef55ffe1d1d6abd926
44
config_hash: 616ec36ed369bae528a26b639b765754

src/gitpod/resources/events.py

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

33
from __future__ import annotations
44

5+
from typing import Iterable
6+
57
import httpx
68

79
from ..types import event_list_params, event_watch_params
@@ -139,6 +141,7 @@ def watch(
139141
*,
140142
environment_id: str | Omit = omit,
141143
organization: bool | Omit = omit,
144+
resource_type_filters: Iterable[event_watch_params.ResourceTypeFilter] | Omit = omit,
142145
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
143146
# The extra values given here take precedence over values defined on the client or passed to this method.
144147
extra_headers: Headers | None = None,
@@ -173,6 +176,11 @@ def watch(
173176
the caller can see within their organization. No task, task execution or service
174177
events are produed.
175178
179+
resource_type_filters: Filters to limit which events are delivered on organization-scoped streams. When
180+
empty, all events for the scope are delivered. When populated, only events
181+
matching at least one filter entry are forwarded. Not supported for
182+
environment-scoped streams; setting this field returns an error.
183+
176184
extra_headers: Send extra headers
177185
178186
extra_query: Add additional query parameters to the request
@@ -188,6 +196,7 @@ def watch(
188196
{
189197
"environment_id": environment_id,
190198
"organization": organization,
199+
"resource_type_filters": resource_type_filters,
191200
},
192201
event_watch_params.EventWatchParams,
193202
),
@@ -314,6 +323,7 @@ async def watch(
314323
*,
315324
environment_id: str | Omit = omit,
316325
organization: bool | Omit = omit,
326+
resource_type_filters: Iterable[event_watch_params.ResourceTypeFilter] | Omit = omit,
317327
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
318328
# The extra values given here take precedence over values defined on the client or passed to this method.
319329
extra_headers: Headers | None = None,
@@ -348,6 +358,11 @@ async def watch(
348358
the caller can see within their organization. No task, task execution or service
349359
events are produed.
350360
361+
resource_type_filters: Filters to limit which events are delivered on organization-scoped streams. When
362+
empty, all events for the scope are delivered. When populated, only events
363+
matching at least one filter entry are forwarded. Not supported for
364+
environment-scoped streams; setting this field returns an error.
365+
351366
extra_headers: Send extra headers
352367
353368
extra_query: Add additional query parameters to the request
@@ -363,6 +378,7 @@ async def watch(
363378
{
364379
"environment_id": environment_id,
365380
"organization": organization,
381+
"resource_type_filters": resource_type_filters,
366382
},
367383
event_watch_params.EventWatchParams,
368384
),

src/gitpod/types/event_watch_params.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
from __future__ import annotations
44

5+
from typing import Iterable
56
from typing_extensions import Annotated, TypedDict
67

8+
from .._types import SequenceNotStr
79
from .._utils import PropertyInfo
10+
from .shared.resource_type import ResourceType
811

9-
__all__ = ["EventWatchParams"]
12+
__all__ = ["EventWatchParams", "ResourceTypeFilter"]
1013

1114

1215
class EventWatchParams(TypedDict, total=False):
@@ -22,3 +25,31 @@ class EventWatchParams(TypedDict, total=False):
2225
the caller can see within their organization. No task, task execution or service
2326
events are produed.
2427
"""
28+
29+
resource_type_filters: Annotated[Iterable[ResourceTypeFilter], PropertyInfo(alias="resourceTypeFilters")]
30+
"""
31+
Filters to limit which events are delivered on organization-scoped streams. When
32+
empty, all events for the scope are delivered. When populated, only events
33+
matching at least one filter entry are forwarded. Not supported for
34+
environment-scoped streams; setting this field returns an error.
35+
"""
36+
37+
38+
class ResourceTypeFilter(TypedDict, total=False):
39+
"""
40+
ResourceTypeFilter restricts which events are delivered for a specific resource type.
41+
"""
42+
43+
creator_ids: Annotated[SequenceNotStr[str], PropertyInfo(alias="creatorIds")]
44+
"""
45+
If non-empty, only events where the resource was created by one of these user
46+
IDs are delivered. Skipped for DELETE operations (creator info is unavailable
47+
after deletion). Events with no creator information are skipped when this filter
48+
is set (fail-closed).
49+
"""
50+
51+
resource_ids: Annotated[SequenceNotStr[str], PropertyInfo(alias="resourceIds")]
52+
"""If non-empty, only events for these specific resource IDs are delivered."""
53+
54+
resource_type: Annotated[ResourceType, PropertyInfo(alias="resourceType")]
55+
"""The resource type to filter for."""

tests/api_resources/test_events.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def test_method_watch_with_all_params(self, client: Gitpod) -> None:
8181
event_stream = client.events.watch(
8282
environment_id="environmentId",
8383
organization=True,
84+
resource_type_filters=[
85+
{
86+
"creator_ids": ["182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"],
87+
"resource_ids": ["182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"],
88+
"resource_type": "RESOURCE_TYPE_UNSPECIFIED",
89+
}
90+
],
8491
)
8592
for item in event_stream:
8693
assert_matches_type(EventWatchResponse, item, path=["response"])
@@ -176,6 +183,13 @@ async def test_method_watch_with_all_params(self, async_client: AsyncGitpod) ->
176183
event_stream = await async_client.events.watch(
177184
environment_id="environmentId",
178185
organization=True,
186+
resource_type_filters=[
187+
{
188+
"creator_ids": ["182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"],
189+
"resource_ids": ["182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"],
190+
"resource_type": "RESOURCE_TYPE_UNSPECIFIED",
191+
}
192+
],
179193
)
180194
async for item in event_stream:
181195
assert_matches_type(EventWatchResponse, item, path=["response"])

0 commit comments

Comments
 (0)