Skip to main content

CommitHeader

Struct CommitHeader 

Source
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: String

The type as written: feat, fix, wip, or the empty string when the subject carries no type: head at all.

§kind: ChangeKind

What 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: bool

Whether 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: String

What 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

Source

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");
Source

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());
Source

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

Source§

fn clone(&self) -> CommitHeader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommitHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CommitHeader

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for CommitHeader

Source§

impl JsonSchema for CommitHeader

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for CommitHeader

Source§

fn eq(&self, other: &CommitHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CommitHeader

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CommitHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more