From 1cf51bb0f3685f08c02f1f0b089c1053cdec4a8a Mon Sep 17 00:00:00 2001 From: PagesCoffy Date: Fri, 6 Sep 2024 08:33:35 +0000 Subject: [PATCH] [Integration][ADO] - Improve on Work Items ID Fetching and Logs (#993) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description What - In the current implementation, we had a bug where work items are related to one single project, instead of correctly matching each work item to the project it was created from. This is because the work item query language was using a SELECT * instead of using a SELECT * FROM project. Also added logs to understand why the integration is throwing 400 errors when it attempts to get the work items IDs Why - How - ## Type of change Please leave one option from the following and delete the rest: - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] New Integration (non-breaking change which adds a new integration) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Non-breaking change (fix of existing functionality that will not change current behavior) - [ ] Documentation (added/updated documentation)

All tests should be run against the port production environment(using a testing org).

### Core testing checklist - [ ] Integration able to create all default resources from scratch - [ ] Resync finishes successfully - [ ] Resync able to create entities - [ ] Resync able to update entities - [ ] Resync able to detect and delete entities - [ ] Scheduled resync able to abort existing resync and start a new one - [ ] Tested with at least 2 integrations from scratch - [ ] Tested with Kafka and Polling event listeners - [ ] Tested deletion of entities that don't pass the selector ### Integration testing checklist - [ ] Integration able to create all default resources from scratch - [ ] Resync able to create entities - [ ] Resync able to update entities - [ ] Resync able to detect and delete entities - [ ] Resync finishes successfully - [ ] If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the `examples` folder in the integration directory. - [ ] If resource kind is updated, run the integration with the example data and check if the expected result is achieved - [ ] If new resource kind is added or updated, validate that live-events for that resource are working as expected - [ ] Docs PR link [here](#) ### Preflight checklist - [ ] Handled rate limiting - [ ] Handled pagination - [ ] Implemented the code in async - [ ] Support Multi account ## Screenshots Screenshot 2024-09-05 at 6 19 03 PM ## API Documentation Provide links to the API documentation used for this integration. --- integrations/azure-devops/CHANGELOG.md | 8 ++++++++ .../azure_devops/client/azure_devops_client.py | 17 ++++++++++------- integrations/azure-devops/pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/integrations/azure-devops/CHANGELOG.md b/integrations/azure-devops/CHANGELOG.md index 58094b0e88..89a72d835c 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.65 (2024-09-05) + + +### Improvements + +- Updated the work item query langauge to fetch works items per project using System.AreaPath instead of all projects in the current implementation (0.1.65) + + ## 0.1.64 (2024-09-05) 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 7cd57476dd..051136d594 100644 --- a/integrations/azure-devops/azure_devops/client/azure_devops_client.py +++ b/integrations/azure-devops/azure_devops/client/azure_devops_client.py @@ -153,7 +153,7 @@ async def generate_work_items(self) -> AsyncGenerator[list[dict[str, Any]], None async for projects in self.generate_projects(): for project in projects: # 1. Execute WIQL query to get work item IDs - work_item_ids = await self._fetch_work_item_ids(project["id"]) + work_item_ids = await self._fetch_work_item_ids(project) logger.info( f"Found {len(work_item_ids)} work item IDs for project {project['name']}" ) @@ -169,7 +169,7 @@ async def generate_work_items(self) -> AsyncGenerator[list[dict[str, Any]], None ) yield work_items - async def _fetch_work_item_ids(self, project_id: str) -> list[int]: + async def _fetch_work_item_ids(self, project: dict[str, Any]) -> list[int]: """ Executes a WIQL query to fetch work item IDs for a given project. @@ -177,18 +177,21 @@ async def _fetch_work_item_ids(self, project_id: str) -> list[int]: :return: A list of work item IDs. """ config = typing.cast(AzureDevopsWorkItemResourceConfig, event.resource_config) - - wiql_query = "SELECT [Id] from WorkItems" + wiql_query = ( + f"SELECT [Id] from WorkItems WHERE [System.AreaPath] = '{project['name']}'" + ) if config.selector.wiql: # Append the user-provided wiql to the WHERE clause - wiql_query += f" WHERE {config.selector.wiql}" + wiql_query += f" AND {config.selector.wiql}" logger.info(f"Found and appended WIQL filter: {config.selector.wiql}") wiql_url = ( - f"{self._organization_base_url}/{project_id}/{API_URL_PREFIX}/wit/wiql" + f"{self._organization_base_url}/{project['id']}/{API_URL_PREFIX}/wit/wiql" + ) + logger.info( + f"Fetching work item IDs for project {project['name']} using WIQL query {wiql_query}" ) - logger.info(f"Fetching work item IDs for project {project_id}") wiql_response = await self.send_request( "POST", wiql_url, diff --git a/integrations/azure-devops/pyproject.toml b/integrations/azure-devops/pyproject.toml index 75d9ce4fae..751dd01891 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.64" +version = "0.1.65" description = "An Azure Devops Ocean integration" authors = ["Matan Geva "]