Skip to content

Commit

Permalink
[Integration][ADO] - Improve on Work Items ID Fetching and Logs (#993)
Browse files Browse the repository at this point in the history
# 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)

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

### 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

<img width="1027" alt="Screenshot 2024-09-05 at 6 19 03 PM"
src="https://github.com/user-attachments/assets/a5d92f75-d2af-489d-8fca-db31cc134af0">
## API Documentation

Provide links to the API documentation used for this integration.
  • Loading branch information
PeyGis authored Sep 6, 2024
1 parent 902a30d commit 1cf51bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
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.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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"
)
Expand All @@ -169,26 +169,29 @@ 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.
:param project_id: The ID of the project.
: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,
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.64"
version = "0.1.65"
description = "An Azure Devops Ocean integration"
authors = ["Matan Geva <[email protected]>"]

Expand Down

0 comments on commit 1cf51bb

Please sign in to comment.