def validate_added_files(added_files, integration_set, playbook_set, script_set, test_playbook_set, is_circle):
    has_schema_problem = False
    for file_path in added_files:
        print "Validating {}".format(file_path)
        if not validate_schema(file_path) or validate_version(file_path):
            has_schema_problem = True

        if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            if not is_test_in_conf_json(file_path) or \
                    (is_circle and not playbook_valid_in_id_set(file_path, test_playbook_set)):
                has_schema_problem = True

            if not is_circle and not is_valid_id(test_playbook_set, collect_ids(file_path), file_path):
                has_schema_problem = True

        elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE) or re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE):
            if is_circle and not script_valid_in_id_set(file_path, script_set):
                has_schema_problem = True

            if not is_circle and not is_valid_id(script_set, get_script_or_integration_id(file_path), file_path):
                has_schema_problem = True

        elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
            if oversize_image(file_path) or not is_existing_image(file_path):
                has_schema_problem = True

            if is_circle and not integration_valid_in_id_set(file_path, integration_set):
                has_schema_problem = True

            if not is_circle and not is_valid_id(integration_set, get_script_or_integration_id(file_path), file_path):
                has_schema_problem = True

        elif re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            if is_circle and not playbook_valid_in_id_set(file_path, playbook_set):
                has_schema_problem = True

            if not is_circle and not is_valid_id(playbook_set, collect_ids(file_path), file_path):
                has_schema_problem = True

        elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE):
            if oversize_image(file_path):
                has_schema_problem = True

        elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \
                re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \
                re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE):
            yml_path, code = get_script_package_data(os.path.dirname(file_path))
            script_data = get_script_data(yml_path, script_code=code)

            if is_circle and not script_valid_in_id_set(yml_path, script_set, script_data):
                has_schema_problem = True

            if not is_circle and not is_valid_id(script_set, get_script_or_integration_id(yml_path),
                                                 yml_path, script_data):
                has_schema_problem = True

    return has_schema_problem
예제 #2
0
def validate_modified_files(integration_set, modified_files, playbook_set,
                            script_set, test_playbook_set, is_circle):
    has_schema_problem = False
    for file_path in modified_files:
        print "Validating {}".format(file_path)
        if not validate_schema(file_path) or changed_id(file_path) or validate_version(file_path) or \
                validate_fromversion_on_modified(file_path):
            has_schema_problem = True
        if not is_release_branch() and not validate_file_release_notes(
                file_path):
            has_schema_problem = True

        if re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            if is_circle and not playbook_valid_in_id_set(
                    file_path, playbook_set):
                has_schema_problem = True

        elif re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE):
            if is_circle and not playbook_valid_in_id_set(
                    file_path, test_playbook_set):
                has_schema_problem = True

        elif re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE):
            if is_circle and not script_valid_in_id_set(file_path, script_set):
                has_schema_problem = True

        elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE):
            if changed_command_name_or_arg(file_path) or changed_context(file_path) or \
                    (is_circle and not script_valid_in_id_set(file_path, script_set)) or \
                    changed_docker_image(file_path):
                has_schema_problem = True

        elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
            if oversize_image(file_path) or is_added_required_fields(file_path) or \
                    changed_command_name_or_arg(file_path) or changed_context(file_path) or \
                    (is_circle and not integration_valid_in_id_set(file_path, integration_set)) or \
                    changed_docker_image(file_path) or not is_existing_image(file_path):
                has_schema_problem = True

        elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE):
            if oversize_image(file_path):
                has_schema_problem = True

        elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \
                re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \
                re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE):
            yml_path, code = get_script_package_data(
                os.path.dirname(file_path))
            script_data = get_script_data(yml_path, script_code=code)

            if changed_command_name_or_arg(yml_path) or changed_context(yml_path) or \
                    (is_circle and not script_valid_in_id_set(yml_path, script_set, script_data)):
                has_schema_problem = True

    return has_schema_problem