Skip to content

Commit

Permalink
refactor(lib): use implicit serde imports
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Aug 13, 2023
1 parent e9aa991 commit c8cf855
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
15 changes: 8 additions & 7 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ use lazy_regex::{
Regex,
};
use serde::ser::{
Serialize,
SerializeStruct,
Serializer,
};
use serde::{
Deserialize,
Serialize,
};

/// Regular expression for matching SHA1 and a following commit message
/// separated by a whitespace.
static SHA1_REGEX: Lazy<Regex> = lazy_regex!(r#"^\b([a-f0-9]{40})\b (.*)$"#);

/// Object representing a link
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Link {
/// Text of the link.
Expand All @@ -43,7 +46,7 @@ pub struct Link {
}

/// A conventional commit footer.
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
struct Footer<'a> {
/// Token of the footer.
///
Expand Down Expand Up @@ -72,9 +75,7 @@ impl<'a> From<&'a ConventionalFooter<'a>> for Footer<'a> {
}

/// Commit signature that indicates authorship.
#[derive(
Debug, Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize,
)]
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct Signature {
/// Name on the signature.
pub name: Option<String>,
Expand All @@ -96,7 +97,7 @@ impl<'a> From<CommitSignature<'a>> for Signature {
}

/// Common commit object that is parsed from a repository.
#[derive(Debug, Default, Clone, PartialEq, serde::Deserialize)]
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Commit<'a> {
/// Commit ID.
Expand Down
16 changes: 10 additions & 6 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use regex::{
Regex,
RegexBuilder,
};
use serde::{
Deserialize,
Serialize,
};
use std::ffi::OsStr;
use std::fs;
use std::path::Path;
Expand All @@ -16,7 +20,7 @@ const CARGO_METADATA_REGEX: &str =
const PYPROJECT_METADATA_REGEX: &str = r"^\[(?:tool)\.git\-cliff\.";

/// Configuration values.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
/// Configuration values about changelog generation.
#[serde(default)]
Expand All @@ -27,7 +31,7 @@ pub struct Config {
}

/// Changelog configuration.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct ChangelogConfig {
/// Changelog header.
pub header: Option<String>,
Expand All @@ -42,7 +46,7 @@ pub struct ChangelogConfig {
}

/// Git configuration
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct GitConfig {
/// Whether to enable parsing conventional commits.
pub conventional_commits: Option<bool>,
Expand Down Expand Up @@ -80,7 +84,7 @@ pub struct GitConfig {
}

/// Parser for grouping commits.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommitParser {
/// Regex for matching the commit message.
#[serde(with = "serde_regex", default)]
Expand All @@ -99,7 +103,7 @@ pub struct CommitParser {
}

/// TextProcessor, e.g. for modifying commit messages.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextProcessor {
/// Regex for matching a text to replace.
#[serde(with = "serde_regex")]
Expand Down Expand Up @@ -130,7 +134,7 @@ impl TextProcessor {
}

/// Parser for extracting links in commits.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LinkParser {
/// Regex for finding links in the commit message.
#[serde(with = "serde_regex")]
Expand Down
6 changes: 5 additions & 1 deletion git-cliff-core/src/release.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::commit::Commit;
use crate::error::Result;
use serde::{
Deserialize,
Serialize,
};

/// Representation of a release.
#[derive(Default, Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Release<'a> {
/// Release version, git tag.
Expand Down

0 comments on commit c8cf855

Please sign in to comment.