Skip to content

Commit

Permalink
Merge pull request #424 from epage/schema
Browse files Browse the repository at this point in the history
feat(config): Add JSON Schema
  • Loading branch information
epage authored Jan 2, 2025
2 parents 7f183ce + 5ba3987 commit 324619f
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 2 deletions.
80 changes: 78 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config",
"type": "object",
"properties": {
"ignore_author_re": {
"type": [
"string",
"null"
]
},
"subject_length": {
"type": [
"integer",
"null"
],
"format": "uint",
"minimum": 0.0
},
"subject_capitalized": {
"type": [
"boolean",
"null"
]
},
"subject_not_punctuated": {
"type": [
"boolean",
"null"
]
},
"imperative_subject": {
"type": [
"boolean",
"null"
]
},
"no_fixup": {
"type": [
"boolean",
"null"
]
},
"no_wip": {
"type": [
"boolean",
"null"
]
},
"hard_line_length": {
"type": [
"integer",
"null"
],
"format": "uint",
"minimum": 0.0
},
"line_length": {
"type": [
"integer",
"null"
],
"format": "uint",
"minimum": 0.0
},
"style": {
"anyOf": [
{
"$ref": "#/definitions/Style"
},
{
"type": "null"
}
]
},
"allowed_types": {
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"allowed_scopes": {
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"merge_commit": {
"type": [
"boolean",
"null"
]
},
"allowed_author_re": {
"type": [
"string",
"null"
]
}
},
"definitions": {
"Style": {
"type": "string",
"enum": [
"conventional",
"none"
]
}
}
}
4 changes: 4 additions & 0 deletions crates/committed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pre-release-replacements = [
{file="../../setup.py", search="COMMITTED_VERSION = .*", replace="COMMITTED_VERSION = '{{version}}'", exactly=1},
]

[features]
unstable-schema = ["dep:schemars"]

[dependencies]
regex = "1.10"
once_cell = "1.19.0"
Expand All @@ -53,6 +56,7 @@ proc-exit = "2.0"
human-panic = "2.0.0"
anstream = "0.6.13"
anstyle = "1.0.6"
schemars = { version = "0.8.21", features = ["preserve_order","semver"], optional = true }

[dev-dependencies]
snapbox = { version = "0.6.19", features = ["cmd", "path"] }
Expand Down
10 changes: 10 additions & 0 deletions crates/committed/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ static DEFAULT_TYPES: &[&str] = &[
Copy, Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, derive_more::Display,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub(crate) enum Style {
#[serde(alias = "Conventional")]
Conventional,
Expand All @@ -16,6 +17,7 @@ pub(crate) enum Style {
#[derive(Clone, Default, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub(crate) struct Config {
pub(crate) ignore_author_re: Option<String>,
pub(crate) subject_length: Option<usize>,
Expand Down Expand Up @@ -167,3 +169,11 @@ impl Config {
self.allowed_author_re.as_deref()
}
}

#[cfg(feature = "unstable-schema")]
#[test]
fn dump_schema() {
let schema = schemars::schema_for!(Config);
let dump = serde_json::to_string_pretty(&schema).unwrap();
snapbox::assert_data_eq!(dump, snapbox::file!("../../../config.schema.json").raw());
}

0 comments on commit 324619f

Please sign in to comment.