def get_script_info(script_path: str, clear_cache: bool = False): """ Gets script information(type, tags, docker image and demisto version). :param script_path: the script yml file path. :param clear_cache: whether to clear cache before getting yml. :return: list of dicts contains the script information. """ script = get_yaml(script_path, cache_clear=clear_cache) script_type = script.get('subtype') if not script_type: script_type = script.get('type') tags = script.get('tags', []) tags = ', '.join(map(str, tags)) from_version = get_from_version(script_path) res = [] if script_type: res.append({'Name': 'Script Type', 'Description': script_type}) if tags: res.append({'Name': 'Tags', 'Description': tags}) if from_version != '': res.append({ 'Name': 'Cortex XSOAR Version', 'Description': from_version }) return res
def get_script_info(script_path): """ Gets script information(type, tags, docker image and demisto version). :param script_path: the script yml file path. :return: list of dicts contains the script information. """ script = get_yaml(script_path) script_type = script.get('subtype') if not script_type: script_type = script.get('type') tags = script.get('tags') tags = ', '.join(map(str, tags)) from_version = get_from_version(script_path) return [{ 'Name': 'Script Type', 'Description': script_type }, { 'Name': 'Tags', 'Description': tags }, { 'Name': 'Demisto Version', 'Description': from_version }]
def update_object_in_id_set(obj_id, obj_data, file_path, instances_set): change_string = run_command("git diff HEAD {}".format(file_path)) is_added_from_version = True if re.search(r'\+fromversion: .*', change_string) else False is_added_to_version = True if re.search(r'\+toversion: .*', change_string) else False file_to_version = get_to_version(file_path) file_from_version = get_from_version(file_path) updated = False for instance in instances_set: instance_id = list(instance.keys())[0] integration_to_version = instance[instance_id].get( 'toversion', '99.99.99') integration_from_version = instance[instance_id].get( 'fromversion', '0.0.0') if obj_id == instance_id: if is_added_from_version or (not is_added_from_version and file_from_version == integration_from_version): if is_added_to_version or (not is_added_to_version and file_to_version == integration_to_version): instance[obj_id] = obj_data[obj_id] updated = True break if not updated: # in case we didn't found then we need to create one add_new_object_to_id_set(obj_id, obj_data, instances_set)
def get_from_version_at_update_rn(path: str): """ Args: path (str): path to yml file, if exists Returns: str. Fromversion if there fromversion key in the yml file. """ if not os.path.isfile(path): print_warning(f'Cannot get file fromversion: "{path}" file does not exist') return return get_from_version(path)
def get_from_version_at_update_rn(path: str) -> Optional[str]: """ param: path (str): path to yml file, if exists :rtype: ``Optional[str]`` :return: Fromversion if there is a fromversion key in the yml file """ if not os.path.isfile(path): print_warning( f'Cannot get file fromversion: "{path}" file does not exist') return None return get_from_version(path)
def collect_changed_ids(integration_ids, playbook_names, script_names, modified_files, id_set): tests_set = set([]) updated_script_names = set([]) updated_playbook_names = set([]) catched_scripts, catched_playbooks = set([]), set([]) script_to_version = {} playbook_to_version = {} integration_to_version = {} for file_path in modified_files: if checked_type(file_path, YML_SCRIPT_REGEXES): name = get_name(file_path) script_names.add(name) script_to_version[name] = (get_from_version(file_path), get_to_version(file_path)) package_name = os.path.dirname(file_path) if glob.glob(package_name + "/*_test.py"): catched_scripts.add(name) tests_set.add('Found a unittest for the script {}'.format(package_name)) elif checked_type(file_path, YML_PLAYBOOKS_NO_TESTS_REGEXES): name = get_name(file_path) playbook_names.add(name) playbook_to_version[name] = (get_from_version(file_path), get_to_version(file_path)) elif checked_type(file_path, INTEGRATION_REGEXES + YML_INTEGRATION_REGEXES): _id = get_script_or_integration_id(file_path) integration_ids.add(_id) integration_to_version[_id] = (get_from_version(file_path), get_to_version(file_path)) if not id_set: with open("./Tests/id_set.json", 'r') as conf_file: id_set = json.load(conf_file) script_set = id_set['scripts'] playbook_set = id_set['playbooks'] integration_set = id_set['integrations'] deprecated_msgs = exclude_deprecated_entities(script_set, script_names, playbook_set, playbook_names, integration_set, integration_ids) for script_id in script_names: enrich_for_script_id(script_id, script_to_version[script_id], script_names, script_set, playbook_set, playbook_names, updated_script_names, updated_playbook_names, catched_scripts, catched_playbooks, tests_set) integration_to_command, deprecated_commands_message = get_integration_commands(integration_ids, integration_set) for integration_id, integration_commands in integration_to_command.items(): enrich_for_integration_id(integration_id, integration_to_version[integration_id], integration_commands, script_set, playbook_set, playbook_names, script_names, updated_script_names, updated_playbook_names, catched_scripts, catched_playbooks, tests_set) for playbook_id in playbook_names: enrich_for_playbook_id(playbook_id, playbook_to_version[playbook_id], playbook_names, script_set, playbook_set, updated_playbook_names, catched_playbooks, tests_set) for new_script in updated_script_names: script_names.add(new_script) for new_playbook in updated_playbook_names: playbook_names.add(new_playbook) affected_ids_strings = { 'scripts': '', 'playbooks': '', 'integrations': '' } if script_names: affected_ids_strings['scripts'] += 'Scripts:\n' + '\n'.join(script_names) if playbook_names: affected_ids_strings['playbooks'] += 'Playbooks:\n' + '\n'.join(playbook_names) if integration_ids: affected_ids_strings['integrations'] += 'Integrations:\n' + '\n'.join(integration_ids) print('The following ids are affected due to the changes you made:') for entity in ['scripts', 'playbooks', 'integrations']: print(affected_ids_strings[entity]) print_color(deprecated_msgs[entity], LOG_COLORS.YELLOW) if deprecated_commands_message: print_color(deprecated_commands_message, LOG_COLORS.YELLOW) return tests_set, catched_scripts, catched_playbooks