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

Format Playbook RN #4735

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changelog/4735.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changes:
- description: |
The command "update-release-notes" will now add Markdown formatting to the release notes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt we discuss that this should only be the case if a flag lit?

of new playbooks that follow the new playbook description template.
type: feature
pr_number: 4735
17 changes: 11 additions & 6 deletions demisto_sdk/commands/update_release_notes/tests/update_rn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ def test_build_rn_template_playbook_new_file(self, mock_master):
Then:
- return a markdown string
"""
expected_result = (
"\n#### Playbooks\n\n##### New: Hello World Playbook\n\n"
"- New: Hello World Playbook description\n"
)
from demisto_sdk.commands.update_release_notes.update_rn import UpdateRN

mock_master.return_value = "1.0.0"
Expand All @@ -249,12 +245,21 @@ def test_build_rn_template_playbook_new_file(self, mock_master):
)
changed_items = {
("Hello World Playbook", FileType.PLAYBOOK): {
"description": "Hello World Playbook description",
"description": (
"This playbook addresses the following alerts:\n"
"Playbook Stages:\nRequirements:\nTriage:\n"
"Early Containment:\nInvestigation:\nContainment:\n"
),
"is_new_file": True,
},
}
release_notes = update_rn.build_rn_template(changed_items)
assert expected_result == release_notes
assert release_notes == (
"\n#### Playbooks\n\n##### New: Hello World Playbook\n\n"
"#### This playbook addresses the following alerts:\n"
"##### Playbook Stages:\n##### Requirements:\n###### Triage:\n"
"###### Early Containment:\n###### Investigation:\n###### Containment:\n\n"
)

@mock.patch.object(UpdateRN, "get_master_version")
def test_build_rn_template_markdown_valid(self, mock_master, mocker):
Expand Down
30 changes: 29 additions & 1 deletion demisto_sdk/commands/update_release_notes/update_rn.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,10 @@ def build_rn_desc(
if is_new_file:
rn_desc = f"##### New: {content_name}\n\n"
if desc:
rn_desc += f"- New: {desc}"
if _type == FileType.PLAYBOOK:
rn_desc += format_playbook_description(desc)
else:
rn_desc += f"- New: {desc}"
if _type in SIEM_ONLY_ENTITIES or content_name.replace(
" ", ""
).lower().endswith(EVENT_COLLECTOR.lower()):
Expand Down Expand Up @@ -1125,3 +1128,28 @@ def get_from_version_at_update_rn(path: str) -> Optional[str]:
)
return None
return get_from_version(path)


def format_playbook_description(desc: str) -> str:
"""Format a playbook description for RN.

:param:
desc (str): The description to format.

:rtype: ``str``
:return:
The formatted description.
"""
desc = f"\n{desc}"
key_phrases = (
(4, "This playbook addresses the following alerts:\n"),
(5, "Playbook Stages:\n"),
(5, "Requirements:\n"),
(6, "Triage:\n"),
(6, "Early Containment:\n"),
(6, "Investigation:\n"),
(6, "Containment:\n"),
)
for hdr, phrase in key_phrases:
desc = desc.replace(f"\n{phrase}", f'\n{"#" * hdr} {phrase}')
return desc.lstrip("\n")
Loading