def test_get_to_version_no_to_version(repo): pack = repo.create_pack('Pack') integration = pack.create_integration('INT', yml={}) with ChangeCWD(repo.path): to_ver = get_to_version(integration.yml.path) assert to_ver == '99.99.99'
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 test_get_to_version_with_to_version(repo): pack = repo.create_pack('Pack') integration = pack.create_integration('INT', yml={'toversion': '4.5.0'}) with ChangeCWD(repo.path): to_ver = get_to_version(integration.yml.path) assert to_ver == '4.5.0'
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