diff --git a/precommend/.pre-commit-config.yaml b/precommend/.pre-commit-config.yaml index b6a7b90..6062c33 100644 --- a/precommend/.pre-commit-config.yaml +++ b/precommend/.pre-commit-config.yaml @@ -73,3 +73,9 @@ repos: rev: v0.16 hooks: - id: validate-pyproject # Validate the contents of pyproject.toml + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.0 + hooks: + - id: check-readthedocs # Validate the given .readthedocs.yml file + - id: check-dependabot # Validate the given dependabot.yml file diff --git a/precommend/rules.py b/precommend/rules.py index b70ba60..311ea14 100644 --- a/precommend/rules.py +++ b/precommend/rules.py @@ -33,6 +33,18 @@ def check_json(ctx): return "check-json" +@rule +def check_dependabot(ctx): + if ctx.filename_exists(".github/dependabot.yml"): + return "check-dependabot" + + +@rule +def check_readthedocs(ctx): + if ctx.filename_exists(".readthedocs.yml"): + return "check-readthedocs" + + @rule def check_toml(ctx): if ctx.tag_exists("toml"): diff --git a/tests/conftest.py b/tests/conftest.py index b0ee255..bc44617 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,3 +12,4 @@ def _dir_fixture(): python_data = dir_fixture("python") cpp_data = dir_fixture("cpp") +generic_data = dir_fixture("generic") diff --git a/tests/data/generic/.github/dependabot.yml b/tests/data/generic/.github/dependabot.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/generic/.github/workflows/ci.yml b/tests/data/generic/.github/workflows/ci.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/generic/.readthedocs.yml b/tests/data/generic/.readthedocs.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_core.py b/tests/test_core.py index 886340e..ff983b1 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -19,6 +19,17 @@ def test_collect_hooks_cpp(monkeypatch, cpp_data): assert "cmake-format" in hooks +def test_collect_hooks_generic(monkeypatch, generic_data): + monkeypatch.chdir(generic_data) + ctx = GenerationContext() + hooks = collect_hooks(ctx) + + assert "actionlint" in hooks + assert "check-dependabot" in hooks + assert "check-readthedocs" in hooks + assert "check-yaml" in hooks + + def test_generate_config_python(monkeypatch, tmp_path, python_data): monkeypatch.chdir(python_data) ctx = GenerationContext() @@ -41,3 +52,17 @@ def test_generate_config_python(monkeypatch, tmp_path, cpp_data): assert "clang-format" in str(output) assert "cmake-format" in str(output) + + +def test_generate_config_generic(monkeypatch, tmp_path, generic_data): + monkeypatch.chdir(generic_data) + ctx = GenerationContext() + hooks = collect_hooks(ctx) + + monkeypatch.chdir(str(tmp_path)) + output = generate_config(hooks) + + assert "actionlint" in str(output) + assert "check-dependabot" in str(output) + assert "check-readthedocs" in str(output) + assert "check-yaml" in str(output)