From 46dd16d12d5a93bcb412e0c5bc901e516a392445 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Tue, 15 Oct 2024 15:46:17 +0200 Subject: [PATCH] fix: coerce current org when using local diff operations --- otterdog/models/__init__.py | 1 + otterdog/models/repository.py | 4 ++++ otterdog/operations/diff_operation.py | 4 ++++ otterdog/operations/local_apply.py | 3 +++ otterdog/operations/local_plan.py | 3 +++ 5 files changed, 15 insertions(+) diff --git a/otterdog/models/__init__.py b/otterdog/models/__init__.py index 1bef6ddf..dfd8b589 100644 --- a/otterdog/models/__init__.py +++ b/otterdog/models/__init__.py @@ -162,6 +162,7 @@ class LivePatchContext: update_webhooks: bool update_secrets: bool update_filter: str + current_org_settings: ModelObject | None expected_org_settings: ModelObject modified_org_settings: dict[str, Change] = dataclasses.field(default_factory=dict) diff --git a/otterdog/models/repository.py b/otterdog/models/repository.py index 8fd98b97..4a5fb6dc 100644 --- a/otterdog/models/repository.py +++ b/otterdog/models/repository.py @@ -923,6 +923,10 @@ def generate_live_patch( else: assert isinstance(current_object, Repository) + if context.current_org_settings is not None: + current_org_settings = cast(OrganizationSettings, context.current_org_settings) + current_object = current_object.coerce_from_org_settings(current_org_settings) + modified_repo: dict[str, Change[Any]] = coerced_object.get_difference_from(current_object) # FIXME: needed to add this hack to ensure that gh_pages_source_path is also present in diff --git a/otterdog/operations/diff_operation.py b/otterdog/operations/diff_operation.py index 144c8203..fd01208f 100644 --- a/otterdog/operations/diff_operation.py +++ b/otterdog/operations/diff_operation.py @@ -225,6 +225,7 @@ def handle(patch: LivePatch) -> None: self.update_webhooks, self.update_secrets, self.update_filter, + current_org.settings if self.coerce_current_org() else None, expected_org.settings, ) expected_org.generate_live_patch(current_org, context, handle) @@ -259,6 +260,9 @@ def handle(patch: LivePatch) -> None: def load_expected_org(self, github_id: str, org_file_name: str) -> GitHubOrganization: return GitHubOrganization.load_from_file(github_id, org_file_name, self.config) + def coerce_current_org(self) -> bool: + return False + async def load_current_org(self, github_id: str, jsonnet_config: JsonnetConfig) -> GitHubOrganization: return await GitHubOrganization.load_from_provider( github_id, jsonnet_config, self.gh_client, self.no_web_ui, self.printer, self.concurrency diff --git a/otterdog/operations/local_apply.py b/otterdog/operations/local_apply.py index 934e1931..0776ef57 100644 --- a/otterdog/operations/local_apply.py +++ b/otterdog/operations/local_apply.py @@ -65,6 +65,9 @@ def pre_execute(self) -> None: def verbose_output(self): return False + def coerce_current_org(self) -> bool: + return True + async def load_current_org(self, github_id: str, jsonnet_config: JsonnetConfig) -> GitHubOrganization: other_org_file_name = jsonnet_config.org_config_file + self.suffix diff --git a/otterdog/operations/local_plan.py b/otterdog/operations/local_plan.py index 64a5c2cc..bb25959a 100644 --- a/otterdog/operations/local_plan.py +++ b/otterdog/operations/local_plan.py @@ -60,6 +60,9 @@ def resolve_secrets(self) -> bool: def setup_github_client(self, org_config: OrganizationConfig) -> GitHubProvider: return GitHubProvider(None) + def coerce_current_org(self) -> bool: + return True + async def load_current_org(self, github_id: str, jsonnet_config: JsonnetConfig) -> GitHubOrganization: other_org_file_name = jsonnet_config.org_config_file + self.suffix