From 872cd6f293b9d3e09c4a9aea994b6e512ebcaa35 Mon Sep 17 00:00:00 2001 From: JeongHunP Date: Sun, 27 Aug 2023 23:46:56 +0900 Subject: [PATCH] Add raw_commit_to_semantic_commit --- repository/src/format.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/repository/src/format.rs b/repository/src/format.rs index 1c668582..1e23ec3f 100644 --- a/repository/src/format.rs +++ b/repository/src/format.rs @@ -1,4 +1,4 @@ -use crate::{raw::SemanticCommit, UNKNOWN_COMMIT_AUTHOR}; +use crate::{raw::RawCommit, raw::SemanticCommit, UNKNOWN_COMMIT_AUTHOR}; use eyre::{eyre, Error}; use regex::Regex; use simperby_core::{reserved::ReservedState, *}; @@ -287,6 +287,26 @@ pub fn fp_from_semantic_commit( } } +pub fn raw_commit_to_semantic_commit(raw_commit: RawCommit) -> SemanticCommit { + let (title, body) = if let Some((title, body)) = raw_commit.message.split_once("\n\n") { + (title.to_string(), body.to_string()) + } else { + (String::new(), String::new()) + }; + SemanticCommit { + title, + body, + diff: if raw_commit.diff.is_none() { + Diff::None + } else { + // TODO: should handle cases, `Reserved`, `NonReserved, `General`. + unimplemented!() + }, + author: raw_commit.author, + timestamp: raw_commit.timestamp, + } +} + #[cfg(test)] mod tests { use super::*;