Expand description
The conventional-commit grammar: one parser, one renderer, one place.
feat(commit)!: the header is parsed once
^^^^ ^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^
word scope breaking subject§Why the parse is total
git log returns what the history holds, and the history holds merges, reverts, and
subjects nobody spelled conventionally. A parser that returned an error for those would
push every caller into deciding what to do with a commit that exists, and the changelog
already made that decision once: an entry it cannot classify is carried whole rather
than dropped, because a changelog that omits what it cannot parse lies about what
happened.
So CommitHeader::parse never fails. It answers with what it found, and
CommitHeader::is_conventional is the separate question a judge asks. The changelog reads
the first; crate::commit::verdict reads the second. Two verdicts, one grammar — which
is the whole reason this module exists rather than a second regular expression in the
gate that checks commits.
use majordomus_cli::commit::CommitHeader;
use majordomus_cli::release::ChangeKind;
let h = CommitHeader::parse("feat(commit)!: the header is parsed once");
assert_eq!(h.kind, ChangeKind::Feat);
assert_eq!(h.scope.as_deref(), Some("commit"));
assert!(h.breaking);
assert_eq!(h.subject, "the header is parsed once");
assert!(h.is_conventional());
// a merge commit is not conventional, and is not damaged by being read
let m = CommitHeader::parse("Merge pull request #249 from korczis/fix/pipelines");
assert!(!m.is_conventional());
assert_eq!(m.subject, "Merge pull request #249 from korczis/fix/pipelines");Structs§
- Commit
Header - The header of a commit message: its first line, taken apart.