Skip to content

Commit

Permalink
change: slightly adjust what settings are displayed in the plan opera…
Browse files Browse the repository at this point in the history
…tion output when resources are added, include model_only fields and exclude settings whose value is null
  • Loading branch information
netomi committed Oct 7, 2024
1 parent 74561ad commit 51d734a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions otterdog/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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):
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion otterdog/operations/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 51d734a

Please sign in to comment.