Skip to content

Commit

Permalink
Merge branch 'port-11075/bugfix-gitlab' of https://github.com/port-la…
Browse files Browse the repository at this point in the history
…bs/ocean into port-11075/bugfix-gitlab
  • Loading branch information
mk-armah committed Oct 30, 2024
2 parents 46fad22 + cbeecb3 commit 879008f
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 1 deletion.
70 changes: 69 additions & 1 deletion integrations/azure-devops/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,73 @@
"many": false
}
}
},
{
"identifier": "release",
"title": "Release",
"icon": "AzureDevops",
"schema": {
"properties": {
"status": {
"title": "Status",
"type": "string",
"icon": "DefaultProperty",
"description": "The current status of the release"
},
"reason": {
"title": "Reason",
"type": "string",
"description": "The reason for the release creation"
},
"createdDate": {
"title": "Created Date",
"type": "string",
"format": "date-time",
"description": "The date and time when the release was created"
},
"modifiedDate": {
"title": "Modified Date",
"type": "string",
"format": "date-time",
"description": "The date and time when the release was last modified"
},
"createdBy": {
"title": "Created By",
"type": "string",
"icon": "User",
"description": "The person who created the release"
},
"modifiedBy": {
"title": "Modified By",
"type": "string",
"icon": "User",
"description": "The person who last modified the release"
},
"definitionName": {
"title": "Definition Name",
"type": "string",
"description": "The name of the release definition"
},
"link": {
"title": "Link",
"type": "string",
"format": "url",
"icon": "AzureDevops",
"description": "Link to the release in Azure DevOps"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {
"project": {
"title": "Project",
"target": "project",
"required": true,
"many": false
}
}
}
]
]
20 changes: 20 additions & 0 deletions integrations/azure-devops/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ resources:
blueprint: '"column"'
relations:
board: .__board.id | gsub(" "; "")
- kind: release
selector:
query: 'true'
port:
entity:
mappings:
identifier: .projectReference.id + "-" + (.id | tostring) | gsub(" "; "")
title: .name
blueprint: '"release"'
properties:
status: .status
reason: .reason
createdDate: .createdOn
modifiedDate: .modifiedOn
createdBy: .createdBy.uniqueName
modifiedBy: .modifiedBy.uniqueName
definitionName: .releaseDefinition.name
link: ._links.web.href | gsub("_release?releaseId="; "")
relations:
project: .projectReference.id | gsub(" "; "")
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ async def generate_pipelines(self) -> AsyncGenerator[list[dict[Any, Any]], None]
pipeline["__projectId"] = project["id"]
yield pipelines

async def generate_releases(self) -> AsyncGenerator[list[dict[str, Any]], None]:
async for projects in self.generate_projects():
for project in projects:
releases_url = (
self._organization_base_url.replace(
"dev.azure.com", "vsrm.dev.azure.com"
)
+ f"/{project['id']}/{API_URL_PREFIX}/release/releases"
)
async for releases in self._get_paginated_by_top_and_skip(releases_url):
yield releases

async def generate_repository_policies(
self,
) -> AsyncGenerator[list[dict[str, Any]], None]:
Expand Down
1 change: 1 addition & 0 deletions integrations/azure-devops/azure_devops/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Kind(StrEnum):
WORK_ITEM = "work-item"
BOARD = "board"
COLUMN = "column"
RELEASE = "release"


PULL_REQUEST_SEARCH_CRITERIA: list[dict[str, Any]] = [
Expand Down
56 changes: 56 additions & 0 deletions integrations/azure-devops/examples/example-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,61 @@
"visibility": "private",
"lastUpdateTime": "2024-01-08T12:07:57.667Z"
}
},
{
"id": 18,
"name": "Release-18",
"status": "abandoned",
"createdOn": "2017-06-16T01:36:20.397Z",
"modifiedOn": "2017-06-16T01:36:21.07Z",
"modifiedBy": {
"id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"displayName": "Chuck Reinhart",
"uniqueName": "[email protected]",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
},
"createdBy": {
"id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"displayName": "Chuck Reinhart",
"uniqueName": "[email protected]",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
},
"variables": {},
"variableGroups": [],
"releaseDefinition": {
"id": 1,
"name": "MyShuttle.CD",
"url": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/definitions/1",
"_links": {
"self": {
"href": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/definitions/1"
},
"web": {
"href": "https://dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_release?definitionId=1"
}
}
},
"description": "Creating Sample release",
"reason": "manual",
"releaseNameFormat": "Release-$(rev:r)",
"keepForever": false,
"definitionSnapshotRevision": 1,
"logsContainerUrl": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/releases/18/logs",
"url": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/releases/18",
"_links": {
"self": {
"href": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/releases/18"
},
"web": {
"href": "https://dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_release?releaseId=18&_a=release-summary"
}
},
"tags": [],
"projectReference": {
"id": "1b6aba50-6176-4df2-a8e3-f0394ec0b0a2",
"name": "Test Project"
}
}
]
21 changes: 21 additions & 0 deletions integrations/azure-devops/examples/example-mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,24 @@ resources:
blueprint: '"column"'
relations:
board: .__board.id | gsub(" "; "")
- kind: release
selector:
query: 'true'
port:
entity:
mappings:
identifier: .id | tostring | gsub(" "; "")
title: .name
blueprint: '"release"'
properties:
status: .status
reason: .reason
createdDate: .createdOn
modifiedDate: .modifiedOn
createdBy: .createdBy.displayName
modifiedBy: .modifiedBy.displayName
tags: .tags
link: ._links.web.href | gsub("_release?releaseId="; "")
relations:
project: .projectReference.id | gsub(" "; "")

25 changes: 25 additions & 0 deletions integrations/azure-devops/examples/example-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,30 @@
"relations": {
"project": "6f84ea1f-e939-477f-8992-4145cb37ed35"
}
},
{
"identifier": "18",
"title": "Release-18",
"blueprint": "release",
"properties": {
"status": "abandoned",
"reason": "manual",
"createdDate": "2017-06-16T01:36:20.397Z",
"modifiedDate": "2017-06-16T01:36:21.07Z",
"createdBy": "Chuck Reinhart",
"modifiedBy": "Chuck Reinhart",
"definitionName": "MyShuttle.CD",
"description": "Creating Sample release",
"releaseNameFormat": "Release-$(rev:r)",
"keepForever": false,
"logsContainerUrl": "https://vsrm.dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_apis/Release/releases/18/logs",
"definitionSnapshotRevision": 1,
"variables": {},
"tags": [],
"link": "https://dev.azure.com/fabrikam/1b6aba50-6176-4df2-a8e3-f0394ec0b0a2/_release?releaseId=18&_a=release-summary"
},
"relations": {
"project": "1b6aba50-6176-4df2-a8e3-f0394ec0b0a2"
}
}
]
8 changes: 8 additions & 0 deletions integrations/azure-devops/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ async def resync_boards(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
yield boards


@ocean.on_resync(Kind.RELEASE)
async def resync_releases(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
azure_devops_client = AzureDevopsClient.create_from_ocean_config()
async for releases in azure_devops_client.generate_releases():
logger.info(f"Resyncing {len(releases)} releases")
yield releases


@ocean.router.post("/webhook")
async def webhook(request: Request) -> dict[str, Any]:
body = await request.json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@
"eventType": "git.push",
}

EXPECTED_RELEASES = [
{
"id": 18,
"name": "Release-18",
"status": "abandoned",
"createdOn": "2017-06-16T01:36:20.397Z",
"modifiedOn": "2017-06-16T01:36:21.07Z",
"description": "Creating Sample release",
"reason": "manual",
"releaseNameFormat": "Release-$(rev:r)",
"keepForever": False,
"projectReference": {"id": "proj1", "name": "Project One"},
}
]

MOCK_FILE_CONTENT = b"file content"
MOCK_FILE_PATH = "/path/to/file.txt"
MOCK_REPOSITORY_ID = "repo123"
Expand Down Expand Up @@ -447,6 +462,40 @@ async def mock_generate_repositories(
assert policies == EXPECTED_POLICIES


@pytest.mark.asyncio
async def test_generate_releases(mock_event_context: MagicMock) -> None:
client = AzureDevopsClient(MOCK_ORG_URL, MOCK_PERSONAL_ACCESS_TOKEN)

# MOCK
async def mock_generate_projects() -> AsyncGenerator[List[Dict[str, Any]], None]:
yield [{"id": "proj1", "name": "Project One"}]

async def mock_get_paginated_by_top_and_skip(
url: str, **kwargs: Any
) -> AsyncGenerator[List[Dict[str, Any]], None]:
if "releases" in url:
yield EXPECTED_RELEASES
else:
yield []

async with event_context("test_event"):
with patch.object(
client, "generate_projects", side_effect=mock_generate_projects
):
with patch.object(
client,
"_get_paginated_by_top_and_skip",
side_effect=mock_get_paginated_by_top_and_skip,
):
# ACT
releases: List[Dict[str, Any]] = []
async for release_batch in client.generate_releases():
releases.extend(release_batch)

# ASSERT
assert releases == EXPECTED_RELEASES


@pytest.mark.asyncio
async def test_get_pull_request() -> None:
client = AzureDevopsClient(MOCK_ORG_URL, MOCK_PERSONAL_ACCESS_TOKEN)
Expand Down

0 comments on commit 879008f

Please sign in to comment.