mirror of
https://github.com/orhun/git-cliff.git
synced 2025-01-05 23:15:53 +03:00
refactor(dep): use git_conventional crate
Signed-off-by: orhun <orhunparmaksiz@gmail.com>
This commit is contained in:
parent
03fbda6732
commit
ab25e1818c
98
Cargo.lock
generated
98
Cargo.lock
generated
@ -49,6 +49,18 @@ version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
version = "0.19.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
|
||||
dependencies = [
|
||||
"funty",
|
||||
"radium",
|
||||
"tap",
|
||||
"wyz",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.67"
|
||||
@ -86,26 +98,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"nom",
|
||||
"nom 5.1.2",
|
||||
"serde",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conventional-commit"
|
||||
version = "0.1.0"
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76b03a1bb7c5518a578ebe2faa24bd08a6390b3cd41f35c54ebcbe1bf443e2c2"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
@ -130,6 +132,23 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
||||
|
||||
[[package]]
|
||||
name = "git-conventional"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b154369d65c23e2b768324e1b0143e991fe1dd3c6d617a26d8a6917303941e88"
|
||||
dependencies = [
|
||||
"doc-comment",
|
||||
"nom 6.1.2",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.13.19"
|
||||
@ -160,7 +179,7 @@ name = "gitolith-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"config",
|
||||
"conventional-commit",
|
||||
"git-conventional",
|
||||
"git2",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
@ -205,15 +224,6 @@ dependencies = [
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.22"
|
||||
@ -320,6 +330,19 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "6.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
|
||||
dependencies = [
|
||||
"bitvec",
|
||||
"funty",
|
||||
"lexical-core",
|
||||
"memchr",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.4"
|
||||
@ -409,6 +432,12 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
@ -496,6 +525,12 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "term_size"
|
||||
version = "0.3.2"
|
||||
@ -569,6 +604,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.5"
|
||||
@ -659,3 +703,9 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "wyz"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||
|
@ -17,7 +17,7 @@ fn main() -> Result<()> {
|
||||
env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
pretty_env_logger::init();
|
||||
let config = Config::parse(args.config)?;
|
||||
let _config = Config::parse(args.config)?;
|
||||
let repository =
|
||||
Repository::init(args.repository.unwrap_or(env::current_dir()?))?;
|
||||
for commit in repository.commits()? {
|
||||
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
thiserror = "1.0"
|
||||
git2 = "0.13"
|
||||
conventional-commit = "0.1.0"
|
||||
git-conventional = "0.9.1"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::error::Result;
|
||||
use conventional_commit::ConventionalCommit;
|
||||
use git2::Commit as GitCommit;
|
||||
use std::str::FromStr;
|
||||
use git_conventional::Commit as ConventionalCommit;
|
||||
|
||||
/// Common commit object that is parsed from a repository.
|
||||
#[derive(Debug)]
|
||||
@ -24,7 +23,7 @@ impl<'a> From<GitCommit<'a>> for Commit {
|
||||
impl Commit {
|
||||
/// Returns a conventional commit using the commit message.
|
||||
pub fn as_conventional(&self) -> Result<ConventionalCommit> {
|
||||
Ok(ConventionalCommit::from_str(&self.message)?)
|
||||
Ok(ConventionalCommit::parse(&self.message)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
/// Gitolith-core related errors that we are exposing to the rest of the
|
||||
/// Library related errors that we are exposing to the rest of the
|
||||
/// workspaces.
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum Error {
|
||||
@ -16,28 +16,34 @@ pub enum Error {
|
||||
/// When commit's not follow the conventional commit structure we throw this
|
||||
/// error.
|
||||
#[error("Cannot parse the commit: `{0}`")]
|
||||
ParseError(#[from] conventional_commit::Error),
|
||||
ParseError(#[from] git_conventional::Error),
|
||||
}
|
||||
|
||||
/// Result type of the gitolith-core libraries.
|
||||
/// Result type of the core library.
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use conventional_commit::{
|
||||
ConventionalCommit,
|
||||
Error as ConventionError,
|
||||
use git_conventional::{
|
||||
Commit,
|
||||
ErrorKind,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
fn mock_function() -> super::Result<ConventionalCommit> {
|
||||
Ok(ConventionalCommit::from_str("test")?)
|
||||
fn mock_function() -> super::Result<Commit<'static>> {
|
||||
Ok(Commit::parse("test")?)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn throw_parse_error() {
|
||||
let actual_error = mock_function().unwrap_err();
|
||||
let expected_error = Error::ParseError(ConventionError::InvalidFormat);
|
||||
assert_eq!(actual_error.to_string(), expected_error.to_string());
|
||||
let expected_error_kind = ErrorKind::InvalidFormat;
|
||||
match actual_error {
|
||||
Error::ParseError(e) => {
|
||||
assert_eq!(expected_error_kind, e.kind());
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ impl Repository {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use conventional_commit::Error as ConventionError;
|
||||
use git_conventional::ErrorKind;
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
@ -80,10 +80,14 @@ mod test {
|
||||
let last_commit = commits.first().unwrap();
|
||||
assert_eq!(Some(get_last_commit_hash()?), last_commit.hash);
|
||||
if let Err(e) = last_commit.as_conventional() {
|
||||
assert_eq!(
|
||||
Error::ParseError(ConventionError::InvalidFormat).to_string(),
|
||||
e.to_string()
|
||||
)
|
||||
match e {
|
||||
Error::ParseError(e) => {
|
||||
assert_eq!(ErrorKind::InvalidFormat, e.kind())
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user