feat: JSON Schema for commitizen configuration (issue #1565) - #2067
Open
FreakyAdy wants to merge 3 commits into
Open
feat: JSON Schema for commitizen configuration (issue #1565)#2067FreakyAdy wants to merge 3 commits into
FreakyAdy wants to merge 3 commits into
Conversation
…ools#1565) - Add scripts/gen_json_schema.py: generates schema from Settings/CzSettings TypedDicts - Add tests/test_json_schema.py: 18 tests validating schema generation, type mapping, defaults, and validation - Add schemas/commitizen-config.schema.json: committed schema (schemastore.org-compatible) - Update pyproject.toml: add jsonschema dependency to test group The schema covers all config keys under [tool.commitizen] including nested customize. All tests pass, ruff clean.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2067 +/- ##
==========================================
+ Coverage 98.24% 99.07% +0.82%
==========================================
Files 61 61
Lines 2799 2799
==========================================
+ Hits 2750 2773 +23
+ Misses 49 26 -23 ☔ View full report in Codecov by Harness. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds JSON Schema generation, validation tests, documentation, and dependencies for Commitizen configuration.
Changes:
- Adds schema generation and drift checking.
- Commits the generated configuration schema.
- Adds schema validation tests and documentation.
- Adds JSON Schema tooling dependencies.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Review summary |
|---|---|
uv.lock |
Missing the newly required types-jsonschema dependency, causing frozen CI installs to fail. |
tests/test_json_schema.py |
Adds schema generation and validation coverage. |
scripts/gen_json_schema.py |
Requires wrapper-schema support and stricter validation for question objects. |
schemas/README.md |
Documents the schema location and usage. |
schemas/commitizen-config.schema.json |
Needs wrapper support, broader question types and choices, and an optional confirm default. |
pyproject.toml |
Adds types-jsonschema, which is not reflected in the lockfile. |
Suppressed comments (1)
tests/test_json_schema.py:77
- CI will not run this drift test for schema- or generator-only edits:
pythonpackage.yml's path filter only treatscommitizen/**,tests/**, and.github/workflows/**as relevant (.github/workflows/pythonpackage.yml:23-26), excludingschemas/**andscripts/**. A stale committed schema can therefore bypass the check. Add these paths or an unconditional schema check.
def test_generated_schema_matches_committed_file(gen_module: Any) -> None:
"""The committed schema must be regenerated whenever the models change."""
expected = SCHEMA_PATH.read_text(encoding="utf-8")
actual = json.dumps(gen_module.generate_schema(), indent=2) + "\n"
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "types-PyYAML>=5.4.3", | ||
| "types-termcolor>=0.1.1", | ||
| "types-colorama>=0.4.15.20240311", | ||
| "types-jsonschema>=4.26.0", |
Comment on lines
+6
to
+7
| "type": "object", | ||
| "properties": { |
Comment on lines
+114
to
+118
| "type": { | ||
| "enum": [ | ||
| "list" | ||
| ] | ||
| }, |
Comment on lines
+125
to
+129
| "choices": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { |
Comment on lines
+182
to
+187
| "required": [ | ||
| "default", | ||
| "message", | ||
| "name", | ||
| "type" | ||
| ] |
Comment on lines
+256
to
+259
| "type": "object", | ||
| "properties": settings_schema["properties"], | ||
| "additionalProperties": True, | ||
| } |
Comment on lines
+145
to
+149
| schema: dict[str, Any] = {"type": "object", "properties": properties} | ||
| required = sorted(getattr(typed_dict, "__required_keys__", ())) | ||
| if required: | ||
| schema["required"] = required | ||
| return schema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a JSON Schema for the commitizen configuration ([tool.commitizen] section in pyproject.toml, or commitizen key in .cz.json/.cz.yaml).
Summary:
SettingsandCzSettingsTypedDicts incommitizen.defaultsplusDEFAULT_SETTINGSruntime defaultsscripts/gen_json_schema.py(run manually or via CI--checkflag)schemas/commitizen-config.schema.json(points tohttps://json.schemastore.org/commitizen.jsonfor future schemastore.org release)tests/test_json_schema.pyvalidating generation, type mapping, defaults, and validationScope (per maintainer discussion in #1565):
commitizensection:[tool.commitizen]table in pyproject.toml (referenced with#:schema comment) orcommitizenkey in.cz.json/.cz.yaml(referenced with$schemakey)customize(CzSettings)Testing:
uv run ruff check --fix .cleanuv run ruff format .cleanAgent disclosure: This PR was developed with AI assistance (Hermes Agent).