git_conventional/
lib.rs

1//! A parser library for the [Conventional Commit] specification.
2//!
3//! [conventional commit]: https://www.conventionalcommits.org
4//!
5//! # Example
6//!
7//! ```rust
8//! use indoc::indoc;
9//!
10//! let message = indoc!("
11//!     docs(example)!: add tested usage example
12//!
13//!     This example is tested using Rust's doctest capabilities. Having this
14//!     example helps people understand how to use the parser.
15//!
16//!     BREAKING CHANGE: Going from nothing to something, meaning anyone doing
17//!     nothing before suddenly has something to do. That sounds like a change
18//!     in your break.
19//!
20//!     Co-Authored-By: Lisa Simpson <lisa@simpsons.fam>
21//!     Closes #12
22//! ");
23//!
24//! let commit = git_conventional::Commit::parse(message).unwrap();
25//!
26//! // You can access all components of the subject.
27//! assert_eq!(commit.type_(), git_conventional::Type::DOCS);
28//! assert_eq!(commit.scope().unwrap(), "example");
29//! assert_eq!(commit.description(), "add tested usage example");
30//!
31//! // And the free-form commit body.
32//! assert!(commit.body().unwrap().contains("helps people understand"));
33//!
34//! // If a commit is marked with a bang (`!`) OR has a footer with the key
35//! // "BREAKING CHANGE", it is considered a "breaking" commit.
36//! assert!(commit.breaking());
37//!
38//! // You can access each footer individually.
39//! assert!(commit.footers()[0].value().contains("That sounds like a change"));
40//!
41//! // Footers provide access to their token and value.
42//! assert_eq!(commit.footers()[1].token(), "Co-Authored-By");
43//! assert_eq!(commit.footers()[1].value(), "Lisa Simpson <lisa@simpsons.fam>");
44//!
45//! // Two types of separators are supported, regular ": ", and " #":
46//! assert_eq!(commit.footers()[2].separator(), " #");
47//! assert_eq!(commit.footers()[2].value(), "12");
48//! ```
49
50#![cfg_attr(docsrs, feature(doc_auto_cfg))]
51#![warn(missing_docs)]
52#![warn(clippy::print_stderr)]
53#![warn(clippy::print_stdout)]
54
55mod commit;
56mod error;
57mod lines;
58mod parser;
59
60pub use commit::{Commit, Footer, FooterSeparator, FooterToken, Scope, Type};
61pub use error::{Error, ErrorKind};
62
63#[doc = include_str!("../README.md")]
64#[cfg(doctest)]
65pub struct ReadmeDoctests;