Ejemplo n.º 1
0
 def check_results(self):
     print(f"::set-output name=has_updated_sources::{str(self.has_updated_sources)}")
     if self.status == "success":
         logging.info("✅ Successfully linted all files without errors")
         config.delete()
     elif self.status == "warning":
         logging.warning("◬ Successfully linted all files, but with ignored errors")
         config.delete()
     else:
         logging.error("❌ Error(s) have been found during linting")
         logging.warning(
             "To disable linters or customize their checks, you can use a .mega-linter.yml file "
             "at the root of your repository"
         )
         logging.warning(
             "More info at https://nvuillam.github.io/mega-linter/configuration/"
         )
         if self.cli is True:
             if config.get("DISABLE_ERRORS", "false") == "true":
                 config.delete()
                 sys.exit(0)
             else:
                 config.delete()
                 sys.exit(self.return_code)
         config.delete()
Ejemplo n.º 2
0
def linter_test_setup(params=None):
    for key in [
        "MEGALINTER_CONFIG",
        "EXTENDS",
        "FILTER_REGEX_INCLUDE",
        "FILTER_REGEX_EXCLUDE",
        "SHOW_ELAPSED_TIME",
    ]:
        if key in os.environ:
            del os.environ[key]
    config.delete()
    if params is None:
        params = {}
    # Root to lint
    sub_lint_root = (
        params["sub_lint_root"]
        if "sub_lint_root" in params
        else f"{os.path.sep}.automation{os.path.sep}test"
    )
    # Root path of default rules
    root_dir = (
        "/tmp/lint"
        if os.path.isdir("/tmp/lint")
        else os.path.relpath(
            os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../.."
        )
    )
    workspace = None
    config_file_path = root_dir + sub_lint_root + os.path.sep + ".mega-linter.yml"
    if os.path.isfile(config_file_path):
        workspace = root_dir + sub_lint_root
    elif params.get("required_config_file", False) is True:
        raise Exception(
            f"[test] There should be a .mega-linter.yml file in test folder {config_file_path}"
        )
    config.init_config(workspace)
    # Ignore report folder
    config.set_value("FILTER_REGEX_EXCLUDE", r"\/report\/")
    # TAP Output deactivated by default
    config.set_value("OUTPUT_FORMAT", "text")
    config.set_value("OUTPUT_DETAIL", "detailed")
    config.set_value("PLUGINS", "")
    config.set_value("VALIDATE_ALL_CODEBASE", "true")
    # Root path of files to lint
    config.set_value(
        "DEFAULT_WORKSPACE",
        (
            config.get("DEFAULT_WORKSPACE") + sub_lint_root
            if config.exists("DEFAULT_WORKSPACE")
            and os.path.isdir(config.get("DEFAULT_WORKSPACE") + sub_lint_root)
            else root_dir + sub_lint_root
        ),
    )
    assert os.path.isdir(config.get("DEFAULT_WORKSPACE")), (
        "DEFAULT_WORKSPACE "
        + config.get("DEFAULT_WORKSPACE")
        + " is not a valid folder"
    )
Ejemplo n.º 3
0
def call_mega_linter(env_vars):
    prev_environ = config.copy()
    usage_stdout = io.StringIO()
    with contextlib.redirect_stdout(usage_stdout):
        # Set env variables
        for env_var_key, env_var_value in env_vars.items():
            config.set_value(env_var_key, env_var_value)
        # Call linter
        mega_linter = Megalinter()
        mega_linter.run()
        # Set back env variable previous values
        for env_var_key, env_var_value in env_vars.items():
            if env_var_key in prev_environ:
                config.set_value(env_var_key, prev_environ[env_var_key])
            else:
                config.delete(env_var_key)
    output = usage_stdout.getvalue().strip()
    print_output(output)
    return mega_linter, output
Ejemplo n.º 4
0
 def tearDown(self):
     config.delete()