Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Fix failure on initialization of actions in case of existence #1012

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ repos:
- id: detect-aws-credentials
- repo: local
hooks:
- id: lint
name: Run linter
description: This hooks runs our linters
entry: make lint
- id: fix lint
name: Fix linter
description: This hooks fixes our linters
entry: make lint/fix
language: system
types:
- python
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.10.10 (2024-09-12)

### Bug Fixes

- Fixed failing on initialization of the integration when one of the actions exists in port

### Improvements

- Added fix lint command to the makefile as well as the pre-commit hook


## 0.10.9 (2024-09-05)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ lint:
$(ACTIVATE) && \
$(call run_checks,.)

lint/fix:
$(ACTIVATE) && \
black .

# Development commands
build:
$(ACTIVATE) && poetry build
Expand Down
58 changes: 28 additions & 30 deletions port_ocean/core/defaults/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def _create_resources(
)
return

created_blueprints, errors = await gather_and_split_errors_from_results(
created_blueprints, blueprint_errors = await gather_and_split_errors_from_results(
(
port_client.create_blueprint(
blueprint, user_agent_type=UserAgentType.exporter
Expand All @@ -131,15 +131,17 @@ async def _create_resources(

created_blueprints_identifiers = [bp["identifier"] for bp in created_blueprints]

if errors:
for error in errors:
if blueprint_errors:
for error in blueprint_errors:
if isinstance(error, httpx.HTTPStatusError):
logger.warning(
f"Failed to create resources: {error.response.text}. Rolling back changes..."
)

raise AbortDefaultCreationError(created_blueprints_identifiers, errors)
created_pages_identifiers = []
raise AbortDefaultCreationError(
created_blueprints_identifiers, blueprint_errors
)

try:
for patch_stage in blueprint_patches:
await asyncio.gather(
Expand All @@ -153,44 +155,40 @@ async def _create_resources(
)
)

await asyncio.gather(
*(port_client.create_action(action) for action in defaults.actions)
except httpx.HTTPStatusError as err:
logger.error(f"Failed to create resources: {err.response.text}. continuing...")
raise AbortDefaultCreationError(created_blueprints_identifiers, [err], [])
try:
created_actions, actions_errors = await gather_and_split_errors_from_results(
(port_client.create_action(action) for action in defaults.actions)
)

await asyncio.gather(
*(
port_client.create_scorecard(blueprint_scorecards["blueprint"], action)
for blueprint_scorecards in defaults.scorecards
for action in blueprint_scorecards["data"]
created_scorecards, scorecards_errors = (
await gather_and_split_errors_from_results(
(
port_client.create_scorecard(
blueprint_scorecards["blueprint"], action
)
for blueprint_scorecards in defaults.scorecards
for action in blueprint_scorecards["data"]
)
)
)

created_pages, pages_errors = await gather_and_split_errors_from_results(
(port_client.create_page(page) for page in defaults.pages)
)
created_pages_identifiers = [
page.get("identifier", "") for page in created_pages
]

if pages_errors:
for error in pages_errors:
errors = actions_errors + scorecards_errors + pages_errors
if errors:
for error in errors:
if isinstance(error, httpx.HTTPStatusError):
logger.warning(
f"Failed to create resources: {error.response.text}. Rolling back changes..."
f"Failed to create resource: {error.response.text}. continuing..."
)

raise AbortDefaultCreationError(
created_blueprints_identifiers,
pages_errors,
created_pages_identifiers,
)
except httpx.HTTPStatusError as err:
logger.error(
f"Failed to create resources: {err.response.text}. Rolling back changes..."
)
raise AbortDefaultCreationError(
created_blueprints_identifiers, [err], created_pages_identifiers
)
except Exception as err:
logger.error(f"Failed to create resources: {err}. continuing...")


async def _initialize_defaults(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.10.9"
version = "0.10.10"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down