From 51d734adfa4317b5f67a959e2386a876448636a7 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 7 Oct 2024 15:29:40 +0200 Subject: [PATCH] change: slightly adjust what settings are displayed in the plan operation output when resources are added, include model_only fields and exclude settings whose value is null --- CHANGELOG.md | 2 ++ otterdog/models/__init__.py | 16 +++++++++++++--- otterdog/operations/plan.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af18162..f6d2698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ ### Changed +- Do not include settings whose values is `null` in the plan operation output when a resource is added. +- Include `model_only` settings in the plan operation output when a resource is added. - Converted status check related settings of a Ruleset into an embedded model object similar to merge queue settings. - Display changes in list properties using sequence comparison. - Converted pull request related settings of a Ruleset into an embedded model object similar to merge queue settings. diff --git a/otterdog/models/__init__.py b/otterdog/models/__init__.py index f221b82..2511d7a 100644 --- a/otterdog/models/__init__.py +++ b/otterdog/models/__init__.py @@ -536,6 +536,7 @@ def keys( self, for_diff: bool = False, for_patch: bool = False, + include_model_only_fields: bool = False, include_nested_models: bool = False, exclude_unset_keys: bool = True, ) -> list[str]: @@ -548,7 +549,7 @@ def keys( if for_patch is True and not self.include_field_for_patch_computation(field): continue - if (for_diff or for_patch) and self.is_model_only(field): + if (for_diff or for_patch) and not include_model_only_fields and self.is_model_only(field): continue if include_nested_models is False and self.is_nested_model(field): @@ -563,16 +564,25 @@ def keys( return result - def to_model_dict(self, for_diff: bool = False, include_nested_models: bool = False) -> dict[str, Any]: + def to_model_dict( + self, + for_diff: bool = False, + include_model_only_fields: bool = False, + include_nested_models: bool = False, + exclude_none_values: bool = False, + ) -> dict[str, Any]: result = {} for key in self.keys( for_diff=for_diff, + include_model_only_fields=include_model_only_fields, include_nested_models=include_nested_models, exclude_unset_keys=True, ): value = self.__getattribute__(key) - if self.is_nested_model_key(key): + if exclude_none_values and not is_set_and_valid(value): + continue + elif self.is_nested_model_key(key): result[key] = cast(ModelObject, value).to_model_dict(for_diff, include_nested_models) elif self.is_embedded_model_key(key) and is_set_and_valid(value): result[key] = cast(EmbeddedModelObject, value).to_model_dict() diff --git a/otterdog/operations/plan.py b/otterdog/operations/plan.py index d40c452..7743c59 100644 --- a/otterdog/operations/plan.py +++ b/otterdog/operations/plan.py @@ -63,7 +63,7 @@ def handle_add_object( self.printer.println() model_header = model_object.get_model_header(parent_object) self.print_dict( - model_object.to_model_dict(for_diff=True), + model_object.to_model_dict(for_diff=True, include_model_only_fields=True, exclude_none_values=True), f"add {model_header}", "+", "green",