Exemple #1
0
def update_object_in_id_set(obj_id, obj_data, file_path, instances_set):
    change_string = run_command("git diff HEAD {0}".format(file_path))
    is_added_from_version = True if re.search('\+fromversion: .*',
                                              change_string) else False
    is_added_to_version = True if re.search('\+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 = 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)
Exemple #2
0
def update_object_in_id_set(obj_id, obj_data, file_path, instances_set):
    change_string = run_command("git diff HEAD {0}".format(file_path))
    is_added_from_version = True if re.search('\+fromversion: .*', change_string) else False
    is_added_to_version = True if re.search('\+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 = 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)
Exemple #3
0
def collect_changed_ids(integration_ids, playbook_names, script_names,
                        modified_files):
    script_to_version = {}
    playbook_to_version = {}
    integration_to_version = {}
    for file_path in modified_files:
        if re.match(SCRIPT_TYPE_REGEX, file_path, re.IGNORECASE) or \
                re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE):
            name = get_name(file_path)
            script_names.add(name)
            script_to_version[name] = (get_from_version(file_path),
                                       get_to_version(file_path))
        elif re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            name = get_name(file_path)
            playbook_names.add(name)
            playbook_to_version[name] = (get_from_version(file_path),
                                         get_to_version(file_path))
        elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
            _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))

    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']

    catched_scripts, catched_playbooks = set([]), set([])
    updated_script_names = set([])
    updated_playbook_names = set([])
    tests_set = set([])

    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 = 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_string = ""
    if script_names:
        affected_ids_string += 'Scripts:\n' + '\n'.join(script_names) + '\n\n'
    if playbook_names:
        affected_ids_string += 'Playbooks:\n' + '\n'.join(
            playbook_names) + '\n\n'
    if integration_ids:
        affected_ids_string += 'Integrations:\n' + '\n'.join(
            integration_ids) + '\n\n'

    print('The following ids are affected due to the changes you made:\n{}'.
          format(affected_ids_string))
    return tests_set, catched_scripts, catched_playbooks
Exemple #4
0
def collect_changed_ids(integration_ids, playbook_names, script_names, modified_files):
    script_to_version = {}
    playbook_to_version = {}
    integration_to_version = {}
    for file_path in modified_files:
        if re.match(SCRIPT_TYPE_REGEX, file_path, re.IGNORECASE):
            name = get_name(file_path)
            script_names.add(name)
            script_to_version[name] = (get_from_version(file_path), get_to_version(file_path))
        elif re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            name = get_name(file_path)
            playbook_names.add(name)
            playbook_to_version[name] = (get_from_version(file_path), get_to_version(file_path))
        elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE):
            _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))

    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']

    catched_scripts, catched_playbooks = set([]), set([])
    updated_script_names = set([])
    updated_playbook_names = set([])
    tests_set = set([])

    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 = 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_string = ""
    if script_names:
        affected_ids_string += 'Scripts:\n' + '\n'.join(script_names) + '\n\n'
    if playbook_names:
        affected_ids_string += 'Playbooks:\n' + '\n'.join(playbook_names) + '\n\n'
    if integration_ids:
        affected_ids_string += 'Integrations:\n' + '\n'.join(integration_ids) + '\n\n'

    print('The following ids are affected due to the changes you made:\n{}'.format(affected_ids_string))
    return tests_set, catched_scripts, catched_playbooks
def collect_changed_ids(integration_ids, playbook_names, script_names,
                        modified_files):
    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))

    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