From f8d26f4ce0296aa0d3285ef8326dcc6410642ae7 Mon Sep 17 00:00:00 2001 From: Terrance DeJesus <99630311+terrancedejesus@users.noreply.github.com> Date: Fri, 10 Feb 2023 13:18:53 -0500 Subject: [PATCH] [Bug] Removed Strip Calls in Favor of F-Strings with Major and Minor Versions (#2541) * removed strip calls in favor of f-strings with major and minor versions * changed variable reference in minor_release of bump-pkg-versions --- detection_rules/devtools.py | 6 ++++-- detection_rules/rule.py | 2 +- tests/test_version_locking.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/detection_rules/devtools.py b/detection_rules/devtools.py index 0b8bb5a6c..16bd2b7d2 100644 --- a/detection_rules/devtools.py +++ b/detection_rules/devtools.py @@ -169,11 +169,13 @@ def bump_versions(major_release: bool, minor_release: bool, patch_release: bool, pkg_ver = Version.parse(pkg_data["registry_data"]["version"]) pkg_kibana_ver = Version.parse(pkg_data["registry_data"]["conditions"]["kibana.version"].lstrip("^")) if major_release: - pkg_data["name"] = str(kibana_ver.bump_major()).rstrip(".0") + major_bump = kibana_ver.bump_major() + pkg_data["name"] = f"{major_bump.major}.{major_bump.minor}" pkg_data["registry_data"]["conditions"]["kibana.version"] = f"^{pkg_kibana_ver.bump_major()}" pkg_data["registry_data"]["version"] = str(pkg_ver.bump_major().bump_prerelease("beta")) if minor_release: - pkg_data["name"] = str(kibana_ver.bump_minor()).rstrip(".0") + minor_bump = kibana_ver.bump_minor() + pkg_data["name"] = f"{minor_bump.major}.{minor_bump.minor}" pkg_data["registry_data"]["conditions"]["kibana.version"] = f"^{pkg_kibana_ver.bump_minor()}" pkg_data["registry_data"]["version"] = str(pkg_ver.bump_minor().bump_prerelease("beta")) pkg_data["registry_data"]["release"] = maturity diff --git a/detection_rules/rule.py b/detection_rules/rule.py index edd8d7d90..791672e26 100644 --- a/detection_rules/rule.py +++ b/detection_rules/rule.py @@ -679,7 +679,7 @@ class BaseRuleContents(ABC): def is_dirty(self) -> Optional[bool]: """Determine if the rule has changed since its version was locked.""" min_stack = Version.parse(self.get_supported_version(), optional_minor_and_patch=True) - existing_sha256 = self.version_lock.get_locked_hash(self.id, str(min_stack).rstrip(".0")) + existing_sha256 = self.version_lock.get_locked_hash(self.id, f"{min_stack.major}.{min_stack.minor}") if existing_sha256 is not None: return existing_sha256 != self.sha256() diff --git a/tests/test_version_locking.py b/tests/test_version_locking.py index 2397305a3..0e2ffa777 100644 --- a/tests/test_version_locking.py +++ b/tests/test_version_locking.py @@ -23,7 +23,7 @@ class TestVersionLock(unittest.TestCase): for rule_id, lock in default_version_lock.version_lock.to_dict().items(): if 'previous' in lock: prev_vers = [Version.parse(v, optional_minor_and_patch=True) for v in list(lock['previous'])] - outdated = [str(v).lstrip(".0") for v in prev_vers if v < min_version] + outdated = [f"{v.major}.{v.minor}" for v in prev_vers if v < min_version] if outdated: errors[rule_id] = outdated