Skip to content

Commit

Permalink
update release notes right template support (#4304)
Browse files Browse the repository at this point in the history
* update release notes now supports the right template for incident fields/types and layouts

* Fixed tests and added changelog

* Removed space

* Fixed test

* More test fixes

* Should be good now

* Removed entirely the release notes with stars

* Fixed tests

* Updated regex to not support **

* Fixed tests after regex change
  • Loading branch information
Shellyber committed May 30, 2024
1 parent dad123a commit cdbcdc5
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .changelog/4304.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed the **update-release-notes** command to support the right template for incident fields, incident types, layouts, generic objects, indicator types, and indicator fields.
type: fix
pr_number: 4304
14 changes: 0 additions & 14 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,6 @@ class FileType(StrEnum):
WIZARDS_DIR,
]

RN_CONTENT_ENTITY_WITH_STARS = [
FileType.CONNECTION,
FileType.INCIDENT_TYPE,
FileType.REPUTATION,
FileType.LAYOUT,
FileType.INCIDENT_FIELD,
FileType.INDICATOR_FIELD,
FileType.TRIGGER,
FileType.GENERIC_DEFINITION,
FileType.GENERIC_MODULE,
FileType.GENERIC_TYPE,
FileType.GENERIC_FIELD,
]

DEFAULT_IMAGE = "demisto_sdk/tests/test_files/default_image.png"

DEFAULT_IMAGE_PREFIX = "data:image/png;base64,"
Expand Down
15 changes: 3 additions & 12 deletions demisto_sdk/commands/common/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
PACK_METADATA_DESC,
PACK_METADATA_NAME,
RELIABILITY_PARAMETER_NAMES,
RN_CONTENT_ENTITY_WITH_STARS,
RN_HEADER_BY_FILE_TYPE,
SUPPORT_LEVEL_HEADER,
XSOAR_CONTEXT_AND_OUTPUTS_URL,
XSOAR_SUPPORT,
Expand Down Expand Up @@ -2730,19 +2728,12 @@ def release_notes_invalid_content_name_header(
@staticmethod
@error_code_decorator
def release_notes_invalid_header_format(content_type: str, pack_name: str):
contents_with_stars = [
RN_HEADER_BY_FILE_TYPE[content] for content in RN_CONTENT_ENTITY_WITH_STARS
]
error = (
f'Please use "demisto-sdk update-release-notes -i Packs/{pack_name}"\n'
"For more information, refer to the following documentation: https://xsoar.pan.dev/docs/documentation/release-notes"
"For more information, refer to the following documentation: "
"https://xsoar.pan.dev/docs/documentation/release-notes"
)

if content_type in contents_with_stars:
error = f'Did not find content items headers under "{content_type}" - might be duo to missing "**" symbols in the header.\n{error}'
else:
error = f'Did not find content items headers under "{content_type}" - might be duo to invalid format.\n{error}'
return error
return f'Did not find content items headers under "{content_type}" - might be duo to invalid format.\n{error}'

@staticmethod
@error_code_decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
r"^#### ([\w ]+)$\n([\w\W]*?)(?=^#### )|^#### ([\w ]+)$\n([\w\W]*)", re.M
)
CONTENT_ITEM_SECTION_REGEX = re.compile(
r"^##### (.+)$\n([\w\W]*?)(?=^##### )|^##### (.+)$\n([\w\W]*)|"
r"^- (?:New: )?\*\*(.+)\*\*$",
r"^##### (.+)$\n([\w\W]*?)(?=^##### )|^##### (.+)$\n([\w\W]*)|" r"^- (?:New: )?$",
re.M,
)

Expand Down
4 changes: 2 additions & 2 deletions demisto_sdk/commands/common/tests/release_notes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def test_validate_headers(mocker, repo):
),
(
"""#### Incident Fields
- *test**
- **test**
- Added x y z""",
"Incident Fields",
{
Expand All @@ -805,7 +805,7 @@ def test_validate_headers(mocker, repo):
"Content type dose not exist",
"Invalid special forms",
"Invalid content type format",
"Invalid special forms missing star",
"Invalid special forms with stars",
],
)
def test_invalid_headers(mocker, repo, content, content_type, expected_result):
Expand Down
22 changes: 15 additions & 7 deletions demisto_sdk/commands/common/tests/test_files/rn_header_test_data
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@
- Ignore the json suffix, it is not a real dashboard.

#### Incident Fields
- **test1**
- New: **test2**
##### test1
- Added x y z

##### New: test2
- New: Added x y z

#### Incident Types
- **test**
##### test
- Added x y z

#### Indicator Fields
- **test**
##### test
- Added x y z

#### Indicator Types
- **test**
##### test
- Added x y z

#### Layouts
- **test**
##### test
- Added x y z

#### Mappers
##### New: test
Expand All @@ -57,4 +64,5 @@
- Ignore the json suffix, it is not a real dashboard.

#### Triggers Recommendations
- **test**
##### test
- Added x y z
68 changes: 44 additions & 24 deletions demisto_sdk/commands/update_release_notes/tests/update_rn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ def test_build_rn_template_integration(self, mocker):
"""
expected_result = (
"\n#### Classifiers\n\n##### Hello World Classifier\n\n- %%UPDATE_RN%%\n"
"\n#### Connections\n\n- **Hello World Connection**\n"
"\n#### Connections\n\n##### Hello World Connection\n\n- %%UPDATE_RN%%\n"
"\n#### Dashboards\n\n##### Hello World Dashboard\n\n- %%UPDATE_RN%%\n"
"\n#### Incident Fields\n\n- **Hello World IncidentField**\n"
"\n#### Incident Types\n\n- **Hello World Incident Type**\n"
"\n#### Indicator Fields\n\n- **Hello World Indicator Field**\n"
"\n#### Indicator Types\n\n- **Hello World Indicator Type**\n"
"\n#### Incident Fields\n\n##### Hello World IncidentField\n\n- %%UPDATE_RN%%\n"
"\n#### Incident Types\n\n##### Hello World Incident Type\n\n- %%UPDATE_RN%%\n"
"\n#### Indicator Fields\n\n##### Hello World Indicator Field\n\n- %%UPDATE_RN%%\n"
"\n#### Indicator Types\n\n##### Hello World Indicator Type\n\n- %%UPDATE_RN%%\n"
"\n#### Integrations\n\n##### Hello World Integration\n\n- %%UPDATE_RN%%\n"
"\n#### Jobs\n\n##### Hello World Job #1\n\n- %%UPDATE_RN%%\n"
"##### Hello World Job #2\n\n- %%UPDATE_RN%%\n"
"\n#### Layouts\n\n- **Hello World Layout**\n"
"- **Second Hello World Layout**\n"
"\n#### Modules\n\n- **Hello World Generic Module**\n"
"\n#### Objects\n\n- **Hello World Generic Definition**\n"
"\n#### Layouts\n\n##### Hello World Layout\n\n- %%UPDATE_RN%%\n"
"##### Second Hello World Layout\n\n- %%UPDATE_RN%%\n"
"\n#### Modules\n\n##### Hello World Generic Module\n\n- %%UPDATE_RN%%\n"
"\n#### Objects\n\n##### Hello World Generic Definition\n\n- %%UPDATE_RN%%\n"
"\n#### Playbooks\n\n##### Hello World Playbook\n\n- %%UPDATE_RN%%\n"
"\n#### Reports\n\n##### Hello World Report\n\n- %%UPDATE_RN%%\n"
"\n#### Scripts\n\n##### Hello World Script\n\n- %%UPDATE_RN%%\n"
Expand Down Expand Up @@ -202,8 +202,8 @@ def test_build_rn_template_integration_for_generic(self, mock_master):
- return a markdown string
"""
expected_result = (
"\n#### Object Fields\n\n- **Sample Generic Field**\n"
"\n#### Object Types\n\n- **Sample Generic Type**\n"
"\n#### Object Fields\n\n##### Sample Generic Field\n\n- %%UPDATE_RN%%\n"
"\n#### Object Types\n\n##### Sample Generic Type\n\n- %%UPDATE_RN%%\n"
)

pack_path = TestRNUpdate.FILES_PATH + "/generic_testing"
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_build_rn_template_file_without_description(self, mock_master):
Then:
- return a markdown string
"""
expected_result = "\n#### Incident Fields\n\n- **Hello World IncidentField**\n"
expected_result = "\n#### Incident Fields\n\n##### Hello World IncidentField\n\n- %%UPDATE_RN%%\n"
from demisto_sdk.commands.update_release_notes.update_rn import UpdateRN

mock_master.return_value = "1.0.0"
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def test_update_rn_new_mapper(repo):
def test_update_rn_new_incident_field(repo):
"""
Case - new incident field, XSOAR, fromversion exists, description exists
Expected - release note should not contain new and version
Expected - release note should contain new and version
"""
pack = repo.create_pack("test_pack")
new_incident_field = pack.create_incident_field(
Expand All @@ -1323,9 +1323,11 @@ def test_update_rn_new_incident_field(repo):
from_version=new_incident_field.read_json_as_dict().get("fromversion"),
)

assert f"- New: **{new_incident_field}**" not in rn_desc
assert (
"##### New:" in rn_desc
) # check if release note contains New - when new file
assert "test_pack" in rn_desc
assert "(Available from Cortex XSOAR 6.5.0)." not in rn_desc
assert "(Available from Cortex XSOAR 6.5.0)." in rn_desc

def test_update_rn_with_deprecated_and_text(self, mocker):
"""
Expand Down Expand Up @@ -1536,19 +1538,27 @@ class TestRNUpdateUnit:
CURRENT_RN = """
#### Incident Types
- **Cortex XDR Incident**
##### Cortex XDR Incident
- %%UPDATE_RN%%
#### Incident Fields
- **XDR Alerts**
##### XDR Alerts
- %%UPDATE_RN%%
#### Object Types
- **Sample GenericType**
##### Sample GenericType
- %%UPDATE_RN%%
#### Object Fields
- **Sample GenericField**
##### Sample GenericField
- %%UPDATE_RN%%
"""
CHANGED_FILES = {
("Cortex XDR Incident", FileType.INCIDENT_TYPE): {
Expand Down Expand Up @@ -1583,21 +1593,31 @@ class TestRNUpdateUnit:
EXPECTED_RN_RES = """
#### Incident Types
- **Cortex XDR Incident**
##### Cortex XDR Incident
- %%UPDATE_RN%%
#### Incident Fields
- **Sample IncidentField**
##### Sample IncidentField
- %%UPDATE_RN%%
##### XDR Alerts
- **XDR Alerts**
- %%UPDATE_RN%%
#### Object Types
- **Sample GenericType**
##### Sample GenericType
- %%UPDATE_RN%%
#### Object Fields
- **Sample GenericField**
##### Sample GenericField
- %%UPDATE_RN%%
#### Integrations
Expand Down
8 changes: 1 addition & 7 deletions demisto_sdk/commands/update_release_notes/update_rn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
DEPRECATED_NO_REPLACE_DESC_REGEX,
EVENT_COLLECTOR,
IGNORED_PACK_NAMES,
RN_CONTENT_ENTITY_WITH_STARS,
RN_HEADER_BY_FILE_TYPE,
SIEM_ONLY_ENTITIES,
XSIAM_DASHBOARDS_DIR,
Expand Down Expand Up @@ -745,13 +744,8 @@ def build_rn_desc(
:return
The release notes description
"""
if _type in RN_CONTENT_ENTITY_WITH_STARS:
if is_new_file:
rn_desc = f"- New: **{content_name}**\n"
else:
rn_desc = f"- **{content_name}**\n"

elif self.is_force:
if self.is_force:
rn_desc = f"## {content_name}\n\n"
rn_desc += f'- {text or "%%UPDATE_RN%%"}\n'
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def test_update_release_notes_incident_field(demisto_client, mocker):
"""
logger_info = mocker.patch.object(logging.getLogger("demisto-sdk"), "info")

expected_rn = "\n" + "#### Incident Fields\n\n" + "- **City**\n"
expected_rn = (
"\n" + "#### Incident Fields\n\n" + "##### City\n\n" + "- %%UPDATE_RN%%\n"
)

runner = CliRunner(mix_stderr=False)
modified_files = {
Expand Down Expand Up @@ -376,7 +378,9 @@ def test_update_release_notes_existing(demisto_client, mocker):
+ "- Azure.CloudIPs Feed Integration.\n"
+ "\n"
+ "#### Incident Fields\n\n"
+ "- **City**\n\n"
+ "##### City\n\n"
+ "- %%UPDATE_RN%%\n"
+ "\n"
)

input_rn = (
Expand Down

0 comments on commit cdbcdc5

Please sign in to comment.