Skip to content

Commit

Permalink
add support for expanding work items
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyGis committed Dec 10, 2024
1 parent a2ba556 commit 4c9b605
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ resources:
- kind: work-item
selector:
query: 'true'
expand: 'All'
port:
entity:
mappings:
Expand Down
8 changes: 8 additions & 0 deletions integrations/azure-devops/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

## 0.1.91 (2024-12-10)


### Improvements

- Added support for expanding the work item response


## 0.1.90 (2024-12-10)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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.
Expand All @@ -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",
}
Expand Down
4 changes: 4 additions & 0 deletions integrations/azure-devops/azure_devops/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integrations/azure-devops/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down

0 comments on commit 4c9b605

Please sign in to comment.