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

Addresses some of #490 Plan output improvement #550

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 21 additions & 4 deletions iambic/output/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import pathlib
from collections import defaultdict
from typing import Any, Dict, List, Optional, Set

from dictdiffer import diff
Expand Down Expand Up @@ -317,7 +318,12 @@ def compile_exceptions_seen(


class ActionSummaries(PydanticBaseModel):
num_actions: Optional[int]
num_create_actions: Optional[int]
num_update_actions: Optional[int]
num_delete_actions: Optional[int]
num_attach_actions: Optional[int]
num_detach_actions: Optional[int]
num_unknown_actions: Optional[int]
num_templates: Optional[int]
num_accounts: Optional[int]
num_exceptions: Optional[int]
Expand All @@ -331,9 +337,20 @@ def compile(cls, changes: List[TemplateChangeDetails]):
ActionSummary.compile_proposed_changes(changes, x)
for x in list([e.value for e in ProposedChangeType])
]
instance.num_actions = sum(
[1 for x in instance.action_summaries if x.count > 0]
)

# Aggregate action type to counts
action_type_to_count = defaultdict(int)
for action_summary in instance.action_summaries:
count_so_far = action_type_to_count[action_summary.action]
count_so_far += action_summary.count
action_type_to_count[action_summary.action] = count_so_far
instance.num_create_actions = action_type_to_count["Create"]
instance.num_update_actions = action_type_to_count["Update"]
instance.num_delete_actions = action_type_to_count["Delete"]
instance.num_attach_actions = action_type_to_count["Attach"]
instance.num_detach_actions = action_type_to_count["Detach"]
instance.num_unknown_actions = action_type_to_count["Unknown"]

instance.num_templates = sum(
[len(x.templates) for x in instance.action_summaries]
)
Expand Down
22 changes: 21 additions & 1 deletion iambic/output/templates/github_summary.jinja2
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# IAMbic Summary
## Change Detection
* {{ iambic.num_actions }} distinct actions.
{% if iambic.num_create_actions > 0 -%}
* {{ iambic.num_create_actions }} Create actions were recorded.
{% endif -%}
{% if iambic.num_update_actions > 0 -%}
* {{ iambic.num_update_actions }} Update actions were recorded.
{% endif -%}
{% if iambic.num_delete_actions > 0 -%}
* {{ iambic.num_delete_actions }} Delete actions were recorded.
{% endif -%}
{% if iambic.num_attach_actions > 0 -%}
* {{ iambic.num_attach_actions }} Attach actions were recorded.
{% endif -%}
{% if iambic.num_detach_actions > 0 -%}
* {{ iambic.num_detach_actions }} Detach actions were recorded.
{% endif -%}
{% if iambic.num_unknown_actions > 0 -%}
* {{ iambic.num_unknown_actions }} Unknown actions were recorded.
{% endif -%}
* {{ iambic.num_templates }} templates with changes.
* {{ iambic.num_accounts }} accounts affected.

{% if iambic.num_exceptions > 0 -%}
## Exceptions
* {{ iambic.num_exceptions }} exceptions were recorded.
{% endif -%}

{% if iambic.num_templates > 0 -%}

Expand Down
22 changes: 21 additions & 1 deletion iambic/output/templates/text_file_summary.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@

{{ "Change Detection" | rich_format("italic blue") }}

* {{ iambic.num_actions | rich_format("blue") }} {{ "distinct actions." | rich_format("blue") }}
{% if iambic.num_create_actions > 0 -%}
* {{ iambic.num_create_actions | rich_format("blue") }} {{ "Create actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_update_actions > 0 -%}
* {{ iambic.num_update_actions | rich_format("blue") }} {{ "Update actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_delete_actions > 0 -%}
* {{ iambic.num_delete_actions | rich_format("blue") }} {{ "Delete actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_attach_actions > 0 -%}
* {{ iambic.num_attach_actions | rich_format("blue") }} {{ "Attach actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_detach_actions > 0 -%}
* {{ iambic.num_detach_actions | rich_format("blue") }} {{ "Detach actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_unknown_actions > 0 -%}
* {{ iambic.num_unknown_actions | rich_format("blue") }} {{ "Unknown actions." | rich_format("blue") }}
{% endif -%}
* {{ iambic.num_templates | rich_format("blue") }} {{ "templates with changes." | rich_format("blue") }}
* {{ iambic.num_accounts | rich_format("blue") }} {{ "accounts affected." | rich_format("blue") }}

{% if iambic.num_exceptions > 0 -%}
{{ "Exceptions" | rich_format("italic blue") }}
* {{ iambic.num_exceptions | rich_format("blue") }} {{ "exceptions were recorded." | rich_format("blue") }}
{% endif -%}

{% if iambic.num_templates > 0 -%}
{{ "IAMbic Change Details" | rich_format("bold blue") }}
{% for action_summary in iambic.action_summaries -%}
Expand Down
22 changes: 21 additions & 1 deletion iambic/output/templates/text_screen_summary.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@

{{ "Change Detection" | rich_format("italic blue") }}

* {{ iambic.num_actions | rich_format("blue") }} {{ "distinct actions." | rich_format("blue") }}
{% if iambic.num_create_actions > 0 -%}
* {{ iambic.num_create_actions | rich_format("blue") }} {{ "Create actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_update_actions > 0 -%}
* {{ iambic.num_update_actions | rich_format("blue") }} {{ "Update actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_delete_actions > 0 -%}
* {{ iambic.num_delete_actions | rich_format("blue") }} {{ "Delete actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_attach_actions > 0 -%}
* {{ iambic.num_attach_actions | rich_format("blue") }} {{ "Attach actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_detach_actions > 0 -%}
* {{ iambic.num_detach_actions | rich_format("blue") }} {{ "Detach actions." | rich_format("blue") }}
{% endif -%}
{% if iambic.num_unknown_actions > 0 -%}
* {{ iambic.num_unknown_actions | rich_format("blue") }} {{ "Unknown actions." | rich_format("blue") }}
{% endif -%}
* {{ iambic.num_templates | rich_format("blue") }} {{ "templates with changes." | rich_format("blue") }}
* {{ iambic.num_accounts | rich_format("blue") }} {{ "accounts affected." | rich_format("blue") }}

{% if iambic.num_exceptions > 0 -%}
{{ "Exceptions" | rich_format("italic blue") }}
* {{ iambic.num_exceptions | rich_format("blue") }} {{ "exceptions were recorded." | rich_format("blue") }}
{% endif -%}

{% if iambic.num_templates > 0 -%}
{{ "IAMbic Change Details" | rich_format("bold blue") }}
{% for action_summary in iambic.action_summaries -%}
Expand Down
10 changes: 5 additions & 5 deletions test/output/test_markdown_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
[
(
get_templates_mixed(),
ActionSummaries(num_accounts=10, num_actions=1, num_templates=2),
ActionSummaries(num_accounts=10, num_create_actions=11, num_templates=2),
),
(
get_update_template(),
ActionSummaries(num_accounts=1, num_actions=1, num_templates=1),
ActionSummaries(num_accounts=1, num_create_actions=2, num_templates=1),
),
],
)
Expand All @@ -28,7 +28,7 @@ def test_get_template_data(
):
template_data = get_template_data(template_change_details)
assert template_data.num_accounts == expected_output.num_accounts
assert template_data.num_actions == expected_output.num_actions
assert template_data.num_create_actions == expected_output.num_create_actions
assert template_data.num_templates == expected_output.num_templates


Expand All @@ -37,11 +37,11 @@ def test_get_template_data(
[
(
get_templates_mixed(),
ActionSummaries(num_accounts=10, num_actions=1, num_templates=2),
ActionSummaries(num_accounts=10, num_create_actions=1, num_templates=2),
),
(
get_update_template(),
ActionSummaries(num_accounts=10, num_actions=1, num_templates=1),
ActionSummaries(num_accounts=10, num_create_actions=1, num_templates=1),
),
],
)
Expand Down