Skip to content

Commit

Permalink
fix: coerce current org when using local diff operations
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Oct 15, 2024
1 parent 7539e08 commit 46dd16d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions otterdog/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions otterdog/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions otterdog/operations/diff_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions otterdog/operations/local_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions otterdog/operations/local_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 46dd16d

Please sign in to comment.