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

Add functions from content #301

Merged
merged 11 commits into from
Mar 30, 2020
22 changes: 21 additions & 1 deletion demisto_sdk/commands/common/tests/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
17 changes: 15 additions & 2 deletions demisto_sdk/commands/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]