From 4c9b605294c5c462f4c2f98abcf991a58f1b9997 Mon Sep 17 00:00:00 2001 From: Pages Coffie Date: Tue, 10 Dec 2024 16:25:32 +0000 Subject: [PATCH] add support for expanding work items --- .../.port/resources/port-app-config.yaml | 1 + integrations/azure-devops/CHANGELOG.md | 8 ++++++++ .../azure_devops/client/azure_devops_client.py | 13 +++++++++++-- integrations/azure-devops/azure_devops/misc.py | 4 ++++ integrations/azure-devops/pyproject.toml | 2 +- .../azure_devops/client/test_azure_devops_client.py | 1 - 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/integrations/azure-devops/.port/resources/port-app-config.yaml b/integrations/azure-devops/.port/resources/port-app-config.yaml index fece9a2097..5f65753452 100644 --- a/integrations/azure-devops/.port/resources/port-app-config.yaml +++ b/integrations/azure-devops/.port/resources/port-app-config.yaml @@ -70,6 +70,7 @@ resources: - kind: work-item selector: query: 'true' + expand: 'All' port: entity: mappings: diff --git a/integrations/azure-devops/CHANGELOG.md b/integrations/azure-devops/CHANGELOG.md index f3d25c5320..752d84023c 100644 --- a/integrations/azure-devops/CHANGELOG.md +++ b/integrations/azure-devops/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 0.1.91 (2024-12-10) + + +### Improvements + +- Added support for expanding the work item response + + ## 0.1.90 (2024-12-10) diff --git a/integrations/azure-devops/azure_devops/client/azure_devops_client.py b/integrations/azure-devops/azure_devops/client/azure_devops_client.py index 981f37dffb..32baa04492 100644 --- a/integrations/azure-devops/azure_devops/client/azure_devops_client.py +++ b/integrations/azure-devops/azure_devops/client/azure_devops_client.py @@ -163,6 +163,9 @@ async def generate_work_items(self) -> AsyncGenerator[list[dict[str, Any]], None """ Retrieves a paginated list of work items within the Azure DevOps organization based on a WIQL query. """ + selector = typing.cast( + AzureDevopsWorkItemResourceConfig, event.resource_config + ).selector async for projects in self.generate_projects(): for project in projects: # 1. Execute WIQL query to get work item IDs @@ -172,7 +175,9 @@ async def generate_work_items(self) -> AsyncGenerator[list[dict[str, Any]], None ) # 2. Fetch work items using the IDs (in batches if needed) work_items = await self._fetch_work_items_in_batches( - project["id"], work_item_ids + project["id"], + work_item_ids, + query_params={"$expand": selector.expand}, ) logger.debug(f"Received {len(work_items)} work items") @@ -217,7 +222,10 @@ async def _fetch_work_item_ids(self, project: dict[str, Any]) -> list[int]: return [item["id"] for item in wiql_response.json()["workItems"]] async def _fetch_work_items_in_batches( - self, project_id: str, work_item_ids: list[int] + self, + project_id: str, + work_item_ids: list[int], + query_params: dict[str, Any] = {}, ) -> list[dict[str, Any]]: """ Fetches work items in batches based on the list of work item IDs. @@ -231,6 +239,7 @@ async def _fetch_work_items_in_batches( batch_ids = work_item_ids[i : i + MAX_WORK_ITEMS_PER_REQUEST] work_items_url = f"{self._organization_base_url}/{project_id}/{API_URL_PREFIX}/wit/workitems" params = { + **query_params, "ids": ",".join(map(str, batch_ids)), "api-version": "7.1-preview.3", } diff --git a/integrations/azure-devops/azure_devops/misc.py b/integrations/azure-devops/azure_devops/misc.py index d7f2d91010..18252a5fdf 100644 --- a/integrations/azure-devops/azure_devops/misc.py +++ b/integrations/azure-devops/azure_devops/misc.py @@ -58,6 +58,10 @@ class AzureDevopsSelector(Selector): description="WIQL query to filter work items. If not provided, all work items will be fetched.", alias="wiql", ) + expand: Literal["None", "Fields", "Relations", "Links", "All"] = Field( + default="All", + description="Expand options for work items. Allowed values are 'None', 'Fields', 'Relations', 'Links' and 'All'. Default value is 'All'.", + ) kind: Literal["work-item"] selector: AzureDevopsSelector diff --git a/integrations/azure-devops/pyproject.toml b/integrations/azure-devops/pyproject.toml index 9799877b55..bc179737d8 100644 --- a/integrations/azure-devops/pyproject.toml +++ b/integrations/azure-devops/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "azure-devops" -version = "0.1.90" +version = "0.1.91" description = "An Azure Devops Ocean integration" authors = ["Matan Geva "] diff --git a/integrations/azure-devops/tests/azure_devops/client/test_azure_devops_client.py b/integrations/azure-devops/tests/azure_devops/client/test_azure_devops_client.py index 66f2003204..82fc2f46d3 100644 --- a/integrations/azure-devops/tests/azure_devops/client/test_azure_devops_client.py +++ b/integrations/azure-devops/tests/azure_devops/client/test_azure_devops_client.py @@ -369,7 +369,6 @@ async def mock_get_paginated_by_top_and_skip( yield [] async with event_context("test_event"): - with patch.object( client, "generate_repositories", side_effect=mock_generate_repositories ):