diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 452a136db..898fb4a6c 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -165,6 +165,20 @@ )$ types: [yaml] +# this hook is autogenerated from a script +# to modify this hook, update `src/check_jsonschema/catalog.py` +# and run `make generate-hooks` or `tox run -e generate-hooks-config` +- id: check-github-discussion + name: Validate GitHub discussion + description: 'Validate GitHub discussion against the schema provided by SchemaStore' + entry: check-jsonschema --builtin-schema vendor.github-discussion + language: python + files: > + (?x)^( + ^\.github/DISCUSSION_TEMPLATE/.+\.ya?ml$ + )$ + types: [yaml] + # this hook is autogenerated from a script # to modify this hook, update `src/check_jsonschema/catalog.py` # and run `make generate-hooks` or `tox run -e generate-hooks-config` diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b72e65f23..a1b58a9ef 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Unreleased - Update vendored schemas: buildkite, gitlab-ci, mergify, renovate, snapcraft (2025-11-23) +- Add GitHub Discussion category forms schema and pre-commit hook. Thanks :user:`edgarrmondragon`! (:pr:`626`) 0.35.0 ------ diff --git a/docs/precommit_usage.rst b/docs/precommit_usage.rst index b7810fa32..f8bc504b0 100644 --- a/docs/precommit_usage.rst +++ b/docs/precommit_usage.rst @@ -211,6 +211,20 @@ Validate GitHub Actions against the schema provided by SchemaStore - id: check-github-actions +``check-github-discussion`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Validate GitHub discussion against the schema provided by SchemaStore + +.. code-block:: yaml + :caption: example config + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.35.0 + hooks: + - id: check-github-discussion + + ``check-github-issue-config`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/usage.rst b/docs/usage.rst index 05b7435c6..bf2c2bda0 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -98,6 +98,7 @@ SchemaStore and other sources: - ``vendor.dependabot`` - ``vendor.drone-ci`` - ``vendor.github-actions`` +- ``vendor.github-discussion`` - ``vendor.github-issue-config`` - ``vendor.github-issue-forms`` - ``vendor.github-workflows`` diff --git a/src/check_jsonschema/builtin_schemas/vendor/github-discussion.json b/src/check_jsonschema/builtin_schemas/vendor/github-discussion.json new file mode 100644 index 000000000..23c2f4ab1 --- /dev/null +++ b/src/check_jsonschema/builtin_schemas/vendor/github-discussion.json @@ -0,0 +1,63 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://json.schemastore.org/github-discussion.json", + "$comment": "https://docs.github.com/en/discussions/managing-discussions-for-your-community/syntax-for-discussion-category-forms", + "additionalProperties": false, + "properties": { + "title": { + "description": "A default title that will be pre-populated in the discussion submission form.", + "type": "string" + }, + "labels": { + "description": "Labels that will automatically be added to discussions created with this template.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "body": { + "description": "Definition of the input types in the discussion form", + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": ["markdown", "textarea", "input", "dropdown", "checkboxes"] + }, + "attributes": { + "type": "object", + "properties": { + "label": { + "type": "string" + }, + "description": { + "type": "string" + }, + "placeholder": { + "type": "string" + } + } + }, + "validations": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + } + } + } + } + } + } + }, + "required": ["body"], + "type": "object" +} diff --git a/src/check_jsonschema/builtin_schemas/vendor/sha256/github-discussion.sha256 b/src/check_jsonschema/builtin_schemas/vendor/sha256/github-discussion.sha256 new file mode 100644 index 000000000..abd222a77 --- /dev/null +++ b/src/check_jsonschema/builtin_schemas/vendor/sha256/github-discussion.sha256 @@ -0,0 +1 @@ +14cf1562338184fa10109cfb4c7855e7070ea6339e5bc3bc83bdb6e1088aca4f \ No newline at end of file diff --git a/src/check_jsonschema/catalog.py b/src/check_jsonschema/catalog.py index dfec96c8f..41b33e0e3 100644 --- a/src/check_jsonschema/catalog.py +++ b/src/check_jsonschema/catalog.py @@ -166,6 +166,16 @@ def _githubusercontent_url(owner: str, repo: str, ref: str, path: str) -> str: "types": "yaml", }, }, + "github-discussion": { + "url": "https://www.schemastore.org/github-discussion.json", + "hook_config": { + "name": "Validate GitHub discussion", + "files": [ + r"^\.github/DISCUSSION_TEMPLATE/.+\.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 155a5407a..de1f5ce49 100644 --- a/tests/acceptance/test_hook_file_matches.py +++ b/tests/acceptance/test_hook_file_matches.py @@ -144,6 +144,16 @@ def get_hook_config(hookid): ), "bad": (".github/actions/foo/other.yaml",), }, + "check-github-discussion": { + "good": ( + ".github/DISCUSSION_TEMPLATE/announcements.yaml", + ".github/DISCUSSION_TEMPLATE/office-hours.yml", + ), + "bad": ( + ".github/discussion.yml", + ".github/DISCUSSION_TEMPLATE/not-a-discussion.txt", + ), + }, "check-github-issue-config": { "good": (".github/ISSUE_TEMPLATE/config.yml",), "bad": ( diff --git a/tests/example-files/hooks/negative/github-discussion/announcements.yml b/tests/example-files/hooks/negative/github-discussion/announcements.yml new file mode 100644 index 000000000..245bb60dc --- /dev/null +++ b/tests/example-files/hooks/negative/github-discussion/announcements.yml @@ -0,0 +1,8 @@ +title: "Office Hours" +not-a-valid-field: "This field is not allowed." +labels: + - "office-hours" +body: + - type: markdown + attributes: + value: "The agenda for this week's office hours is as follows: ..." diff --git a/tests/example-files/hooks/positive/github-discussion/announcements.yml b/tests/example-files/hooks/positive/github-discussion/announcements.yml new file mode 100644 index 000000000..b17cce77a --- /dev/null +++ b/tests/example-files/hooks/positive/github-discussion/announcements.yml @@ -0,0 +1,7 @@ +title: "Office Hours" +labels: + - "office-hours" +body: + - type: markdown + attributes: + value: "The agenda for this week's office hours is as follows: ..."