diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 28a2597d5..cb8bb9b26 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -190,6 +190,20 @@ )$ types: [yaml] +# this hook is autogenerated from a script +# to modify this hook, update `src/check_jsonschema/catalog.py` +# and run `just generate-hooks` or `tox run -e generate-hooks-config` +- id: check-github-funding + name: Validate GitHub funding + description: 'Validate GitHub funding against the schema provided by SchemaStore' + entry: check-jsonschema --builtin-schema vendor.github-funding + language: python + files: > + (?x)^( + ^\.github/FUNDING\.ya?ml$ + )$ + types: [yaml] + # this hook is autogenerated from a script # to modify this hook, update `src/check_jsonschema/catalog.py` # and run `just generate-hooks` or `tox run -e generate-hooks-config` diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f06f69d72..7e76ec70c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Unreleased - Update vendored schemas: buildkite, circle-ci, citation-file-format, gitlab-ci, meltano, mergify, renovate, snapcraft (2026-10-18) +- Add a ``check-github-funding`` pre-commit hook. (:issue:`725`) - Added support for Python 3.15 . - Removed support for Python 3.10 . - The build backend has been updated from setuptools to flit. diff --git a/docs/precommit_usage.rst b/docs/precommit_usage.rst index 2eddbde6c..88dc6dfe9 100644 --- a/docs/precommit_usage.rst +++ b/docs/precommit_usage.rst @@ -239,6 +239,20 @@ Validate GitHub discussion against the schema provided by SchemaStore - id: check-github-discussion +``check-github-funding`` +~~~~~~~~~~~~~~~~~~~~~~~~ + +Validate GitHub funding against the schema provided by SchemaStore + +.. code-block:: yaml + :caption: example config + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.38.2 + hooks: + - id: check-github-funding + + ``check-github-issue-config`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/usage.rst b/docs/usage.rst index 3031c9921..d4c602ad1 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -100,6 +100,7 @@ SchemaStore and other sources: - ``vendor.drone-ci`` - ``vendor.github-actions`` - ``vendor.github-discussion`` +- ``vendor.github-funding`` - ``vendor.github-issue-config`` - ``vendor.github-issue-forms`` - ``vendor.github-workflows`` diff --git a/src/check_jsonschema/builtin_schemas/vendor/github-funding.json b/src/check_jsonschema/builtin_schemas/vendor/github-funding.json new file mode 100644 index 000000000..01806185e --- /dev/null +++ b/src/check_jsonschema/builtin_schemas/vendor/github-funding.json @@ -0,0 +1,113 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://json.schemastore.org/github-funding.json", + "$comment": "https://docs.github.com/en/github/administering-a-repository/displaying-a-sponsor-button-in-your-repository", + "additionalProperties": false, + "description": "You can add a sponsor button in your repository to increase the visibility of funding options for your open source project.", + "properties": { + "community_bridge": { + "title": "LFX Mentorship (formerly CommunityBridge)", + "description": "Project name on CommunityBridge.", + "type": "string", + "minLength": 1 + }, + "github": { + "title": "GitHub Sponsors", + "description": "You can add one organization and up to four sponsored developers.", + "oneOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "minItems": 1, + "maxItems": 5, + "uniqueItems": true, + "items": { + "type": "string", + "minLength": 1 + } + } + ] + }, + "issuehunt": { + "title": "IssueHunt", + "description": "Username on IssueHunt.", + "type": "string", + "minLength": 1 + }, + "ko_fi": { + "title": "Ko-fi", + "description": "Username on Ko-fi.", + "type": "string", + "minLength": 1 + }, + "liberapay": { + "title": "Liberapay", + "description": "Username on Liberapay.", + "type": "string", + "minLength": 1 + }, + "open_collective": { + "title": "Open Collective", + "description": "Username on Open Collective.", + "type": "string", + "minLength": 1 + }, + "patreon": { + "title": "Patreon", + "description": "Username on Patreon.", + "type": "string", + "minLength": 1 + }, + "tidelift": { + "title": "Tidelift", + "description": "Platform and package on Tidelift, following the format `PLATFORM-NAME/PACKAGE-NAME`.", + "type": "string", + "pattern": "^(npm|pypi|rubygems|maven|packagist|nuget)/.+$" + }, + "polar": { + "title": "Polar", + "description": "Username on Polar.", + "type": "string", + "minLength": 1 + }, + "buy_me_a_coffee": { + "title": "Buy Me a Coffee", + "description": "Username on Buy Me a Coffee.", + "type": "string", + "minLength": 1 + }, + "thanks_dev": { + "title": "thanks.dev", + "description": "Maintainer profile on thanks.dev", + "type": "string", + "pattern": "^u/gh/.+$" + }, + "custom": { + "title": "Custom URL or URL's", + "description": "Link or links where funding is accepted on external locations.", + "oneOf": [ + { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + { + "type": "array", + "minItems": 1, + "maxItems": 4, + "uniqueItems": true, + "items": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + } + ] + } + }, + "title": "GitHub Funding", + "type": "object" +} diff --git a/src/check_jsonschema/builtin_schemas/vendor/sha256/github-funding.sha256 b/src/check_jsonschema/builtin_schemas/vendor/sha256/github-funding.sha256 new file mode 100644 index 000000000..387099a1e --- /dev/null +++ b/src/check_jsonschema/builtin_schemas/vendor/sha256/github-funding.sha256 @@ -0,0 +1 @@ +90d83f41c25a0029653a7ba64080aa6f3973527eed533f18f5b932a425bc802b \ No newline at end of file diff --git a/src/check_jsonschema/catalog.py b/src/check_jsonschema/catalog.py index 80cbd7e9d..d9c1ae3b7 100644 --- a/src/check_jsonschema/catalog.py +++ b/src/check_jsonschema/catalog.py @@ -204,6 +204,16 @@ def _gitlab_raw_url(repo: str, file_path: str, ref: str) -> str: "types": "yaml", }, }, + "github-funding": { + "url": "https://www.schemastore.org/github-funding.json", + "hook_config": { + "name": "Validate GitHub funding", + "files": [ + r"^\.github/FUNDING\.ya?ml$", + ], + "types": "yaml", + }, + }, "github-issue-config": { "url": "https://www.schemastore.org/github-issue-config.json", "hook_config": { diff --git a/tests/acceptance/test_hook_file_matches.py b/tests/acceptance/test_hook_file_matches.py index 7c007a707..b1e9866fc 100644 --- a/tests/acceptance/test_hook_file_matches.py +++ b/tests/acceptance/test_hook_file_matches.py @@ -164,6 +164,18 @@ def get_hook_config(hookid): ".github/DISCUSSION_TEMPLATE/not-a-discussion.txt", ), }, + "check-github-funding": { + "good": ( + ".github/FUNDING.yml", + ".github/FUNDING.yaml", + ), + "bad": ( + ".github/funding.yml", + ".github/funding.yaml", + "FUNDING.yml", + ".github/FUNDING.txt", + ), + }, "check-github-issue-config": { "good": (".github/ISSUE_TEMPLATE/config.yml",), "bad": ( diff --git a/tests/example-files/hooks/negative/github-funding/funding.yml b/tests/example-files/hooks/negative/github-funding/funding.yml new file mode 100644 index 000000000..edfe1f2ca --- /dev/null +++ b/tests/example-files/hooks/negative/github-funding/funding.yml @@ -0,0 +1,2 @@ +github: [octocat] +unknown_funding_platform: invalid diff --git a/tests/example-files/hooks/positive/github-funding/funding.yml b/tests/example-files/hooks/positive/github-funding/funding.yml new file mode 100644 index 000000000..bfda13982 --- /dev/null +++ b/tests/example-files/hooks/positive/github-funding/funding.yml @@ -0,0 +1,4 @@ +github: [octocat] +patreon: octocat +ko_fi: octocat +custom: ["https://example.com/donate"]