pub struct CommitHeader {
pub word: String,
pub kind: ChangeKind,
pub scope: Option<String>,
pub breaking: bool,
pub subject: String,
}Expand description
The header of a commit message: its first line, taken apart.
word is the type as the author wrote it and kind is what that word names; they
differ exactly when the word is not one of the eleven the convention defines, and
keeping both is what lets a reader see wip(site): halfway through as its author typed
it while a judge still reports that wip is not a type.
use majordomus_cli::commit::CommitHeader;
use majordomus_cli::release::ChangeKind;
let h = CommitHeader::parse("fix(plan): the fingerprint names what moved");
assert_eq!(h.word, "fix");
assert_eq!(h.kind, ChangeKind::Fix);
assert_eq!(h.scope.as_deref(), Some("plan"));
assert!(!h.breaking);
assert_eq!(h.subject, "the fingerprint names what moved");Fields§
§word: StringThe type as written: feat, fix, wip, or the empty string when the subject
carries no type: head at all.
kind: ChangeKindWhat Self::word names; ChangeKind::Other for a word the convention does not
define, and for a subject with no head.
scope: Option<String>The parenthesised scope, when there is one.
breaking: boolWhether the head carried the ! that marks a breaking change. The BREAKING CHANGE:
trailer is a property of the body and is read by crate::commit::CommitMessage.
subject: StringWhat the commit says it did. For a header that does not parse this is the whole first line, unchanged, and for an unknown type word it keeps the word: nothing that the author wrote is dropped on the way through.
Implementations§
Source§impl CommitHeader
impl CommitHeader
Sourcepub fn parse(subject: &str) -> CommitHeader
pub fn parse(subject: &str) -> CommitHeader
Read one subject line. Never fails; see the module documentation for why.
use majordomus_cli::commit::CommitHeader;
// a conventional subject comes apart
assert_eq!(CommitHeader::parse("docs: one line").subject, "one line");
// and one that is not is carried whole rather than split at a colon in the sentence
let m = CommitHeader::parse("Merge branch 'x' of host: into y");
assert_eq!(m.word, "");
assert_eq!(m.subject, "Merge branch 'x' of host: into y");Sourcepub fn is_conventional(&self) -> bool
pub fn is_conventional(&self) -> bool
Whether this header is a conventional commit: a type word the convention defines,
followed by an optional scope, an optional !, : , and a subject.
use majordomus_cli::commit::CommitHeader;
assert!(CommitHeader::parse("docs: the page the recipes cite").is_conventional());
assert!(!CommitHeader::parse("update stuff").is_conventional());
assert!(!CommitHeader::parse("wip(site): halfway").is_conventional());Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render a header back to the line it came from.
The round trip is exact for every conventional header, which is the property that lets a planner build a header, a validator judge the rendered line, and both be talking about the same commit.
use majordomus_cli::commit::CommitHeader;
for line in ["feat(commit)!: derived", "fix: one thing", "perf(http): fewer reads"] {
assert_eq!(CommitHeader::parse(line).render(), line);
}Trait Implementations§
Source§impl Clone for CommitHeader
impl Clone for CommitHeader
Source§fn clone(&self) -> CommitHeader
fn clone(&self) -> CommitHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CommitHeader
impl Debug for CommitHeader
Source§impl<'de> Deserialize<'de> for CommitHeader
impl<'de> Deserialize<'de> for CommitHeader
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for CommitHeader
Source§impl JsonSchema for CommitHeader
impl JsonSchema for CommitHeader
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for CommitHeader
impl PartialEq for CommitHeader
Source§fn eq(&self, other: &CommitHeader) -> bool
fn eq(&self, other: &CommitHeader) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for CommitHeader
impl Serialize for CommitHeader
impl StructuralPartialEq for CommitHeader
Auto Trait Implementations§
impl Freeze for CommitHeader
impl RefUnwindSafe for CommitHeader
impl Send for CommitHeader
impl Sync for CommitHeader
impl Unpin for CommitHeader
impl UnsafeUnpin for CommitHeader
impl UnwindSafe for CommitHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.