diff --git a/demisto_sdk/commands/common/tests/tools_test.py b/demisto_sdk/commands/common/tests/tools_test.py index fc2681fbda..467689a1ce 100644 --- a/demisto_sdk/commands/common/tests/tools_test.py +++ b/demisto_sdk/commands/common/tests/tools_test.py @@ -5,7 +5,8 @@ from demisto_sdk.commands.common.git_tools import git_path from demisto_sdk.commands.common import tools from demisto_sdk.commands.common.constants import PACKS_PLAYBOOK_YML_REGEX, PACKS_TEST_PLAYBOOKS_REGEX -from demisto_sdk.commands.common.tools import get_matching_regex, server_version_compare, find_type, get_dict_from_file +from demisto_sdk.commands.common.tools import get_matching_regex, server_version_compare, find_type,\ + get_dict_from_file, LOG_COLORS, get_last_release_version from demisto_sdk.tests.constants_test import VALID_REPUTATION_FILE, VALID_SCRIPT_PATH, VALID_INTEGRATION_TEST_PATH, \ VALID_PLAYBOOK_ID_PATH, VALID_LAYOUT_PATH, VALID_WIDGET_PATH, VALID_INCIDENT_FIELD_PATH, VALID_DASHBOARD_PATH, \ INDICATORFIELD_EXTRA_FIELDS, VALID_INCIDENT_TYPE_PATH @@ -125,3 +126,22 @@ class TestServerVersionCompare: @pytest.mark.parametrize("left, right, answer", INPUTS) def test_server_version_compare(self, left, right, answer): assert server_version_compare(left, right) == answer + + +class TestPrintColor: + def test_print_color(self, mocker): + mocker.patch('builtins.print') + + tools.print_color('test', LOG_COLORS.GREEN) + + print_args = print.call_args[0][0] + assert print_args == u'{}{}{}'.format(LOG_COLORS.GREEN, 'test', LOG_COLORS.NATIVE) + + +class TestReleaseVersion: + def test_get_last_release(self, mocker): + mocker.patch('demisto_sdk.commands.common.tools.run_command', return_value='1.2.3\n4.5.6\n3.2.1\n20.0.0') + + tag = get_last_release_version() + + assert tag == '20.0.0' diff --git a/demisto_sdk/commands/common/tools.py b/demisto_sdk/commands/common/tools.py index 17962b33ed..423b7ef678 100644 --- a/demisto_sdk/commands/common/tools.py +++ b/demisto_sdk/commands/common/tools.py @@ -58,8 +58,8 @@ def get_yml_paths_in_dir(project_dir: str, error_msg: str,) -> Tuple[list, str]: # print srt in the given color -def print_color(str, color): - print(color + str + LOG_COLORS.NATIVE) +def print_color(obj, color): + print(u'{}{}{}'.format(color, obj, LOG_COLORS.NATIVE)) def print_error(error_str): @@ -648,3 +648,16 @@ def run_command_os(command: str, cwd: Path, env: dict = os.environ) -> Tuple[str return '', str(e), 1 return stdout, stderr, process.returncode + + +def get_last_release_version(): + """ + Get latest release tag (xx.xx.xx) + + :return: tag + """ + tags = run_command('git tag').split('\n') + tags = [tag for tag in tags if re.match(r'\d+\.\d+\.\d+', tag) is not None] + tags.sort(key=LooseVersion, reverse=True) + + return tags[0]