pub struct CommitMessage {
pub header: CommitHeader,
pub body: String,
pub trailers: Vec<CommitTrailer>,
}Expand description
A commit message taken apart: header, body, trailers.
use majordomus_cli::commit::CommitMessage;
let m = CommitMessage::parse("feat(a): a thing\n\nThe body.\n\nRefs: I1305\n");
assert_eq!(m.header.subject, "a thing");
assert_eq!(m.body, "The body.");
assert_eq!(m.trailers.len(), 1);Fields§
§header: CommitHeaderThe first line, parsed.
body: StringEverything between the header and the trailer block, with surrounding blank lines removed. Empty when the message is a subject alone.
trailers: Vec<CommitTrailer>The Key: value lines of the final paragraph, in the order they were written.
Implementations§
Source§impl CommitMessage
impl CommitMessage
Sourcepub fn parse(text: &str) -> CommitMessage
pub fn parse(text: &str) -> CommitMessage
Read a whole commit message. Total, like CommitHeader::parse: what cannot be read as a
header or a trailer is body, and nothing is an error.
use majordomus_cli::commit::CommitMessage;
// a last paragraph of prose is body, not trailers, even though git would disagree
let m = CommitMessage::parse("fix(x): a thing\n\nThe reason: it was wrong.");
assert!(m.trailers.is_empty());
assert_eq!(m.body, "The reason: it was wrong.");Sourcepub fn trailer(&self, key: &str) -> Option<&str>
pub fn trailer(&self, key: &str) -> Option<&str>
The value of the first trailer with this key, compared case-insensitively.
use majordomus_cli::commit::CommitMessage;
let m = CommitMessage::parse("fix(x): a\n\nb\n\nCo-Authored-By: Someone <s@example.org>\n");
assert_eq!(m.trailer("co-authored-by"), Some("Someone <s@example.org>"));
assert_eq!(m.trailer("Refs"), None);Sourcepub fn breaking(&self) -> bool
pub fn breaking(&self) -> bool
Whether this commit declares itself breaking, by either spelling: the ! in the
header or the trailer in the message.
use majordomus_cli::commit::CommitMessage;
assert!(CommitMessage::parse("feat(api)!: the route moved").breaking());
assert!(CommitMessage::parse("feat(api): moved\n\nBREAKING CHANGE: it moved").breaking());
assert!(!CommitMessage::parse("feat(api): moved").breaking());Trait Implementations§
Source§impl Clone for CommitMessage
impl Clone for CommitMessage
Source§fn clone(&self) -> CommitMessage
fn clone(&self) -> CommitMessage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommitMessage
impl Debug for CommitMessage
Source§impl<'de> Deserialize<'de> for CommitMessage
impl<'de> Deserialize<'de> for CommitMessage
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for CommitMessage
Source§impl JsonSchema for CommitMessage
impl JsonSchema for CommitMessage
Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreSource§impl PartialEq for CommitMessage
impl PartialEq for CommitMessage
Source§fn eq(&self, other: &CommitMessage) -> bool
fn eq(&self, other: &CommitMessage) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for CommitMessage
impl Serialize for CommitMessage
impl StructuralPartialEq for CommitMessage
Auto Trait Implementations§
impl Freeze for CommitMessage
impl RefUnwindSafe for CommitMessage
impl Send for CommitMessage
impl Sync for CommitMessage
impl Unpin for CommitMessage
impl UnsafeUnpin for CommitMessage
impl UnwindSafe for CommitMessage
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
Mutably borrows from an owned value. Read more
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
Compare self to
key and return true if they are equal.